var activid;
var PrivatchatTon = false;
var startscroller = false;
var scrollertext = "";

NS6=false;
IE4=(document.all);
if (!IE4) {NS6=(document.getElementById);}
NS4=(document.layers);
var isMac = (navigator.userAgent.indexOf("Mac") != -1);
var olOp = (navigator.userAgent.toLowerCase().indexOf('opera') > -1 && document.createTextNode);  // Opera 7
var olNs4 = (navigator.appName=='Netscape' && parseInt(navigator.appVersion) == 4);
var olNs6 = (document.getElementById) ? true : false;
var olKq = (olNs6 && /konqueror/i.test(navigator.userAgent));
var olIe4 = (document.all) ? true : false;
var olIe5 = false; 
var olIe55 = false;
var ie=typeof document.all=='object';
var dom=document.getElementById;
var docRoot = 'document.body';
var timesaygoodbye ="";

floatX=10;
floatY=10;
delayspeed=1;
ifloatX=floatX;
ifloatY=floatY;
lastX=-1;
lastY=-1;

function sendMagComment(obj,id,seite){
	 obj = $(obj);
	
	
	if(obj.value.length > 2){
		
	new Ajax.Request('/remote/comment/MagazineComment.php?text='+escape(obj.value)+'&id='+id,  {
		method:'get',
	onLoading: function(){
	
	$('CommentText').disabled = true;
	$('CommentTextArea').innerHTML =	'Übertragung gestartet';
	
	}
	,
	onSuccess: function(transport){       
    
		$('CommentTextArea').innerHTML = 'Übertragung erfolgreich';
		 
		 ajaxpage('/kinkats/User_tab.BerichteKommentare?noframe=1&id='+id+'&seite='+seite, 'berichtekommentare');
		 }
		 ,     
		 
		onFailure: function(){ 
		
		$('CommentTextArea').innerHTML = 'Übertragung fehlgeschlagen';
		
		}   
	}
	
	); 
	

	}
	
}

function sendComment(obj,usrid,seite){
	 obj = $(obj);
	
	
	if(obj.value.length > 2){
		
	new Ajax.Request('/remote/comment/comment.php?text='+escape(obj.value)+'&usrid='+usrid,  {
		method:'get',
	onLoading: function(){
	
	$('CommentText').disabled = true;
	$('CommentTextArea').innerHTML =	'Übertragung gestartet';
	
	}
	,
	onSuccess: function(transport){       
    
		$('CommentTextArea').innerHTML = 'Übertragung erfolgreich';
		 
		 ajaxpage('/kinkats/User_tab.Kommentare?noframe=1&usr_id='+usrid+'&seite='+seite, 'rightcolumn');
		 }
		 ,     
		 
		onFailure: function(){ 
		
		$('CommentTextArea').innerHTML = 'Übertragung fehlgeschlagen';
		
		}   
	}
	
	); 
	

	}
	
}

function sendGalerieComment(obj,usrid,galid,seite){
	 obj = $(obj);
	
	
	if(obj.value.length > 2){
		
	$('CommentText').disabled = true;
	$('CommentTextArea').innerHTML =	'Übertragung gestartet';
		
	new Ajax.Request('/remote/comment/Galeriecomment.php?text='+escape(obj.value)+'&usrid='+usrid+'&galid='+galid,  {
		method:'get',
	onSuccess: function(transport){
    
		$('CommentTextArea').innerHTML = 'Übertragung erfolgreich';
		 
		 ajaxpage('/kinkats/User_tab.GalerieKommentare?noframe=1&usr_id='+usrid+'&seite='+seite+'&gal_id='+galid, 'GalerieKommentare');
		 }
		 ,     
		 
		onFailure: function(){ 
		
		$('CommentTextArea').innerHTML = 'Übertragung fehlgeschlagen';
		
		}   
	}
	
	); 
	

	}
	
}




function Addfavorit(typ,usrid){
	 
	
	new Ajax.Request('/remote/favorit/fav.php?typ='+typ+'&usrid='+usrid,  {
		method:'get',
	onLoading: function(){
	
	$('fav').src = '/images/default/_navigation/nav_fav02.gif';
	
	}
	,
	onSuccess: function(transport){       
    
    if(typ == 'add'){
		 $('fav').src = '/images/default/_navigation/nav_fav00.gif';
		 $('favlink').href = 'Javascript:Addfavorit(\'rem\','+usrid+')';
		}else{
		 $('fav').src = '/images/default/_navigation/nav_fav01.gif';
		 $('favlink').href = 'Javascript:Addfavorit(\'add\','+usrid+')';
		}
		 
		 }
		 ,     
		 
		onFailure: function(){ 
		
		
		
		}   
	}
	
	); 
	
	
}


function findePos(el,r){
var pos=0;
if(el.offsetParent){
while(el.offsetParent){
pos+=r?el.offsetTop:el.offsetLeft;
el=el.offsetParent;
}
}
else if(el.y)pos+=r?el.y:el.x;
return pos;
}


function zeigVersteckIframe(el){

obj = document.getElementById('killSelect');

ifrS=obj.style;
ifrS.top=findePos(el,1)+'px';
ifrS.left=findePos(el)+'px';
ifrS.height=el.offsetHeight+'px';
ifrS.width=el.offsetWidth+'px';

showObject(obj);

}

function openpayment(URL) {
		winX=500;
		winY=580;
		posX=(screen.width/2)-(winX/2);
		posY=(screen.height/2)-(winY/2)-30;
		if (posY < 0){posY = 0;}
		winFeatures='width='+winX+', height='+winY+',innerHeight='+winY+',innerWidth='+winX+', left='+posX+', screenX='+posX+', top='+posY+', screenY='+posY+', toolbar=0, location=0, directories=0, status=0, menuBar=0, scrollBars=0, resizable=0';
		win = window.open(URL,'Payment',winFeatures);
		win.focus();
	}


function high(LinkName,color){ 
	document.getElementById(LinkName).style.background=color;
	document.getElementById(LinkName).style.cursor='pointer';
	}
	
function low(LinkName,color) 	{ 
	document.getElementById(LinkName).style.background=color; 
	}


function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

function CountTextarea(obj,counter,max) {
	StrLen = obj.value.length
	if (StrLen == 1 && obj.value.substring(0,1) == " ") {
    	obj.value = ""
        StrLen = 0
    }
    if (StrLen > max ) {
    	obj.value = obj.value.substring(0,max)
        CharsLeft = 0
    } else {
        CharsLeft = max - StrLen
    }
  $(counter).innerHTML = CharsLeft;
}

function checkCheckBox(obj2,dummy, text)
{
	
	 eval("obj = document.getElementById('"+dummy+"');");

	
	if(obj.checked!=true){
		alert(text);
		return false;
	}
	Datenuebertragen(obj2)
	return true;
}

function CheckAgb(obj2,dummy, text)
{
	
	 eval("obj = document.getElementById('"+dummy+"');");

	
	if(obj.checked!=true){
		alert(text);
		return false;
	}

	DatenuebertragenPayment(obj2)
	return true;
}


function postcolor(color,obj)
{	
	insert('[color:'+color+']', '[/color]');
}

function addSmilie(text)
{

		insert(text,'');

 }

function forumsuche(){
	
	sendurl = "User_ForumSuch_Ergebnis?noframe=1&";
		
		
		
		if(document.forms[0].suchtyp[0].checked == true){
		  
		  if(document.forms[0].Bdate.value != ""){
		 	datecheck = checkDate(document.forms[0].Bdate.value)
		 
		  }else{
		  datecheck = true;
		  }
		  
		 }else if(document.forms[0].suchtyp[1].checked == true){
		  
		  if(document.forms[0].Tdate.value != ""){
		 	datecheck = checkDate(document.forms[0].Tdate.value)
		  }else{
		  datecheck = true;
		  }
		}
		
		if(datecheck == true){
		
				for (i=0;i< document.forms[0].length;i++){
				
				if(document.forms[0].elements[i].type != "button"){
				
				if(document.forms[0].elements[i].type == "radio"){
					
					if(document.forms[0].elements[i].checked == true){
					
					sendurl += document.forms[0].elements[i].name+"="+document.forms[0].elements[i].value;
					
					}
					
					if(i < (document.forms[0].length-2)){sendurl += "&";}
				
				}else{
				sendurl += document.forms[0].elements[i].name+"="+document.forms[0].elements[i].value;
				}
			
			if(i < (document.forms[0].length-2)){sendurl += "&";}
			
			 }
		}
		
		parent.treads.location.href=sendurl
		
		}else{
		alert('Das angegebene Datums Format ist Falsch bitte ändern (Beispiel:01.03.2004)');
		}
}


function checkDate(string)
{
    if(!string) return null;
    string += '';

    string = string.replace(/[^0-9^\.]/g, '');

    var split = string.split(".");
    var day = parseInt(split[0], 10);
    var month = parseInt(split[1] || 0, 10);
    var year = parseInt(split[2] || 0, 10);

    if(isNaN(year)) year = getFullYear();;

    var check = new Date(year, month - 1, day);
    var day2 = check.getDate();
    var year2 = getFullYear(check);
    var month2 = check.getMonth() + 1;

    if ( year2 == year && month == month2 && day == day2 ) return true;
    return false;
}

function getFullYear(date)
{
    if(!date) date = new Date();
    if(typeof date.getFullYear != 'undefined') return date.getFullYear();
    var year = date.getYear();
    if(year < 1000) year += 2000;
    return year;
}

function postcode(tag,obj)
{
         switch(tag)
         {
	               case "b":
								insert('[b]', '[/b]');
	                    break;
	               case "i":
								insert('[i]', '[/i]');
	                    break;
	               case "u":
								insert('[u]', '[/u]');
	                    break;
	               case "center":
								insert('[center]', '[/center]');
	                    break;
	               case "quote":
								insert('[quote]', '[/quote]');
	                    break;
	                    
			case "youtube":
								insert('[youtube]', '[/youtube]');
			break;
              }
}

	function openPopup(theURL,winName,winX,winY) {
		
		posX=(screen.width/2)-(winX/2);
		posY=(screen.height/2)-(winY/2)-30;
		if (posY < 0){posY = 0;}
		winFeatures='width='+winX+', height='+winY+',innerHeight=580,innerWidth=0, left='+posX+', screenX='+posX+', top='+posY+', screenY='+posY+', toolbar=0, location=0, directories=0, status=0, menuBar=0, resizable=0, scrollbars=yes';
		win = window.open(theURL,winName,winFeatures);
		win.focus();
	}


function Info(anfrage) {
 	
 obj = document.getElementById('Userinfo');	
 obj.innerHTML = anfrage;

}


function InfoAusgabe(obj,ausgabe) {
 	
 obj = document.getElementById(obj);	
 
  	if(isObject(obj)){
 			obj.innerHTML = ausgabe;
		}
}

function pause(millisecondi)
{
    var now = new Date();
    var exitTime = now.getTime() + millisecondi;

    while(true)
    {
        now = new Date();
        if(now.getTime() > exitTime) return;
    }
}



function PrintChatTeaser(usrid,usrlogin,code,bild){

URL = "/happy/User_PrivatChat/"+usrid+"?client=1&popup=1";

ChatTeaser = true;

annehmen = 'javascript:openPopup(\''+URL+'\',\'Chat\',\'500\',\'475\');hideok(document.getElementById(\'PrivatChatmsg\'));';

ablehen = 'javascript:hide(document.getElementById(\'PrivatChatmsg\'),\''+usrid+'\',\''+code+'\',\'[I][B]Leider wurde deine Chat Anfrage abgelehnt![/B][/I]\');cleartime();';


	if(PrivatchatTon == true){
		
		ton =  '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="1" height="1" id="getMp3" align="middle">';
		ton += '<param name="allowScriptAccess" value="sameDomain" />';
		ton += '<param name="movie" value="/Sound/getmp3.swf?file=/Sound/sound1.mp3" />';
		ton += '<param name="quality" value="high" />';
	  ton += '<embed src="/Sound/getmp3.swf?file=/Sound/sound1.mp3" quality="high" width="1" height="1" name="getMp3" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		ton += '</object>';
	
	
	}else{
	
		ton = '';
	
	}


var info =  '<table class="KontaktContent KontaktTop" style="width:240px;height:100px" border="0" cellspacing="0" cellpadding="0" align="center">';
		info += '<tr><td valign="top">';
		info += '<table class="KontaktCommand" style="width:240px;height:100px" border="0" cellspacing="0" cellpadding="0" align="center"><tr>';
		info += '<td width="65" style="padding:1px;padding-right:3px" rowspan="3"><img style="border-left: 1px solid #000000;border-right: 1px solid #000000;border-top: 1px solid #000000;border-bottom: 1px solid #000000;" src="'+bild+'"></td>';
		info += '<td valign="top" ><b>';
		info += usrlogin+'</b><br>Will mit dir Chatten<br>';
		info += '</td></tr><tr><td style="padding-top:3px" valign="top">';
		info += '<a href="'+annehmen+'"><img border="0" src="'+images+'/Community/Buttons/chatAnnehmen.jpg"></a>';
		info += '</td></tr><tr><td style="padding-top:3px" valign="top">';
		info += '<a href="'+ablehen+'"><img border="0" src="'+images+'/Community/Buttons/chatAblehnen.jpg"></a>';
		info += '</td>';
		info += '</tr></table>'+ton;
		info += '</td>';
		info += '</tr>';
		info += '</table>';

Nachricht(info);

time = "hide(parent.document.getElementById('PrivatChatmsg'),'"+usrid+"','"+code+"','[I][B]Leider ist der User nicht vorm Rechner![/B][/I]')";

timesaygoodbye = setTimeout("eval(time)",60000);

}

function hideok(obj){
		
		ChatTeaser = false;
				
		if(ie && !olOp)kill = document.getElementById('killSelect');
		if(ie && !olOp)hideObject(kill);
		
		hideObject(obj);
		clearTimeout(timesaygoodbye);
	
	}


function hide(obj,usr_id_empf , chatcode , text){
		
		ChatTeaser = false;
		
		if(ie && !olOp)kill = document.getElementById('killSelect');
		if(ie && !olOp)hideObject(kill);
		
		hideObject(obj);
		
		SendChatMsg(text , usr_id_empf , chatcode)
		clearTimeout(timesaygoodbye);
	
	}


function cleartime(){
	
		clearTimeout(timesaygoodbye);
	
	}


function Nachricht(anfrage) {
 	
 define();
 	
 obj = document.getElementById('PrivatChatmsg');
 	
 obj.innerHTML = anfrage;
 obj.style.left = floatX;
 obj.style.top =  floatY;
 obj.style.width = 240+"px";
 obj.style.height = 100+"px";
 obj.style.position = 'absolute';
 showObject(obj);
 	
 	if(ie && !olOp)zeigVersteckIframe(obj);
 
 adjust();
}


function Datenuebertragen(objForm) {
 	
 obj = document.getElementById('overDiv');
 
 define();

 obj.style.background = "#FFFFFF";
 obj.style.backgroundImage = 'url(/images/default/loading.gif)';
 obj.style.left = floatX;
 obj.style.top =  floatY;
 obj.style.width 	= 218+"px";
 obj.style.height  = 71+"px";
 obj.style.border = "";
 obj.style.padding  = 0;
 
 showObject(obj);
 
 	if(ie && !olOp)zeigVersteckIframe(obj);

 adjust2(); 
  
 for (var i = 0; i < objForm.length; ++i) {
  
	  if(objForm.elements[i].type == "submit" && objForm.elements[i].type == "image"){
	
	  		objForm.elements[i].disabled = true;
	
		}
  
	}
 
}


function DatenuebertragenPayment(objForm) {
 	
 obj = document.getElementById('overDiv');
 
 define();

 obj.style.background = "#FFFFFF";
 obj.style.backgroundImage = 'url(/images/default/PaymentLoading.gif)';
 obj.style.left = floatX;
 obj.style.top =  floatY;
 obj.style.width 	= 218+"px";
 obj.style.height  = 71+"px";
 obj.style.border = "";
 obj.style.padding  = 0;
 
 showObject(obj);
 
 	if(ie && !olOp)zeigVersteckIframe(obj);

 adjust2(); 
  
 for (var i = 0; i < objForm.length; ++i) {
  
	  if(objForm.elements[i].type == "submit" && objForm.elements[i].type == "image"){
	
	  		objForm.elements[i].disabled = true;
	
		}
  
	}
 
}



function showObject(obj) {
	
	runHook("showObject", FBEFORE);

	var theObj=(olNs4 ? obj : obj.style);
	theObj.visibility = 'visible';

	runHook("showObject", FAFTER);
}

function checkLoginAGB(dummy)
{
	if(dummy.checked!=true){
		alert('Du musst Die Agb akzeptieren.');
		return false;
	}
}


function adjust() {
if ((NS4) || (NS6)) {
if (lastX==-1 || delayspeed==0)
{
lastX=window.pageXOffset + floatX;
lastY=window.pageYOffset + floatY;
}
else
{
var dx=Math.abs(window.pageXOffset+floatX-lastX);
var dy=Math.abs(window.pageYOffset+floatY-lastY);
var d=Math.sqrt(dx*dx+dy*dy);
var c=Math.round(d/10);
if (window.pageXOffset+floatX>lastX) {lastX=lastX+delayspeed+c;}
if (window.pageXOffset+floatX<lastX) {lastX=lastX-delayspeed-c;}
if (window.pageYOffset+floatY>lastY) {lastY=lastY+delayspeed+c;}
if (window.pageYOffset+floatY<lastY) {lastY=lastY-delayspeed-c;}
}
if (NS4){
document.layers['PrivatChatmsg'].pageX = lastX;
document.layers['PrivatChatmsg'].pageY = lastY;
}
if (NS6){
document.getElementById('PrivatChatmsg').style.left=lastX;
document.getElementById('PrivatChatmsg').style.top=lastY;
}
}
else if (IE4){
if (lastX==-1 || delayspeed==0)
{
lastX=document.body.scrollLeft + floatX;
lastY=document.body.scrollTop + floatY;
}
else
{
var dx=Math.abs(document.body.scrollLeft+floatX-lastX);
var dy=Math.abs(document.body.scrollTop+floatY-lastY);
var d=Math.sqrt(dx*dx+dy*dy);
var c=Math.round(d/10);
if (document.body.scrollLeft+floatX>lastX) {lastX=lastX+delayspeed+c;}
if (document.body.scrollLeft+floatX<lastX) {lastX=lastX-delayspeed-c;}
if (document.body.scrollTop+floatY>lastY) {lastY=lastY+delayspeed+c;}
if (document.body.scrollTop+floatY<lastY) {lastY=lastY-delayspeed-c;}
}
document.all['PrivatChatmsg'].style.posLeft = lastX;
document.all['PrivatChatmsg'].style.posTop = lastY;
document.getElementById('killSelect').style.posLeft = lastX;
document.getElementById('killSelect').style.posTop = lastY;
} 
setTimeout('adjust()',50);
}


function adjust2() {
if ((NS4) || (NS6)) {
if (lastX==-1 || delayspeed==0)
{
lastX=window.pageXOffset + floatX;
lastY=window.pageYOffset + floatY;
}
else
{
var dx=Math.abs(window.pageXOffset+floatX-lastX);
var dy=Math.abs(window.pageYOffset+floatY-lastY);
var d=Math.sqrt(dx*dx+dy*dy);
var c=Math.round(d/10);
if (window.pageXOffset+floatX>lastX) {lastX=lastX+delayspeed+c;}
if (window.pageXOffset+floatX<lastX) {lastX=lastX-delayspeed-c;}
if (window.pageYOffset+floatY>lastY) {lastY=lastY+delayspeed+c;}
if (window.pageYOffset+floatY<lastY) {lastY=lastY-delayspeed-c;}
}

if (NS4){
document.layers['overDiv'].pageX = lastX;
document.layers['overDiv'].pageY = lastY;
}
if (NS6){
document.getElementById('overDiv').style.left=lastX;
document.getElementById('overDiv').style.top=lastY;
}
}
else if (IE4){

if (lastX==-1 || delayspeed==0)
{
	lastX=document.body.scrollLeft + floatX;
	lastY=document.body.scrollTop + floatY;
}
else
{
	var dx=Math.abs(document.body.scrollLeft+floatX-lastX);
	var dy=Math.abs(document.body.scrollTop+floatY-lastY);
	var d=Math.sqrt(dx*dx+dy*dy);
	var c=Math.round(d/10);
if (document.body.scrollLeft+floatX>lastX) {lastX=lastX+delayspeed+c;}
if (document.body.scrollLeft+floatX<lastX) {lastX=lastX-delayspeed-c;}
if (document.body.scrollTop+floatY>lastY) {lastY=lastY+delayspeed+c;}
if (document.body.scrollTop+floatY<lastY) {lastY=lastY-delayspeed-c;}
}
document.all['overDiv'].style.posLeft = lastX;
document.all['overDiv'].style.posTop = lastY;
document.getElementById('killSelect').style.posLeft = lastX;
document.getElementById('killSelect').style.posTop = lastY;

} 
setTimeout('adjust2()',50);
}


function define()
{

if ((NS4) || (NS6)) 
{ 

floatY=Math.round((window.innerHeight-20)/2)-Math.round(106/2)

}

if (IE4) 

{


floatY=Math.round((document.body.offsetHeight-20)/2)-Math.round(106/2)

}


floatX = 380;

}


function isObject(a) 
 {
     return (typeof a == 'object' && !!a) || isFunction(a);
 }
 
 
function insert(aTag, eTag) {
  var input = document.forms['posting'].elements['text'];
  input.focus();
  /* für Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfügen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);      
    }
    range.select();
  }
  /* für neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfügen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* für die übrigen Browser */
  else
  {
    /* Abfrage der Einfügeposition */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Einfügen des Formatierungscodes */
    var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
  }
}

