
// globale Instanz von XMLHttpRequest
var xmlHttp = false;

// XMLHttpRequest-Instanz erstellen
// ... f�r Internet Explorer
try {
    xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
    try {
        xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
        xmlHttp  = false;
    }
}
// ... f�r Mozilla, Opera und Safari
if (!xmlHttp  && typeof XMLHttpRequest != 'undefined') {
    xmlHttp = new XMLHttpRequest();
}


function actionFollow(what,who){
	   
   	$.get("/ajax/follow/start.php", { what: what , who: who},
	   function(data){
		 if(data == 'following'){
			 
		 }
		 
	   });
}

function actionUnfollow(what){
   $.get("/ajax/follow/stop.php", { what: what},
	   function(data){
	   //	alert(data);
	   });
}

$(document).ready(function() {
	
	$(".badge-holder .badge a").prettyPhoto({ modal: false, opacity: 0.5, theme: 'light_rounded', social_tools: ''
	});
	
	$(".sessionexpired-hint").prettyPhoto({ modal: true, theme: 'light_rounded', social_tools: '', callback: function(){
		document.location='';	
	}
	});
	
	$('.removeable-item').append('<span class="remover"></span>');
	$('.removeable-item .remover').click(function(){
		$(this).parent().find('.hi').remove();
		$(this).parent().parent('form').submit();
	});
	
	$('.autocomplete.members').autocomplete('/ajax/members.php',{width: 270, selectFirst: true, formatItem: formatItem, formatResult: formatResult});
	

	$(".follow-settings").prettyPhoto({modal: true});
	
	function formatItem(row){
		var output = row[0];
		
		if(row[2])
		output += " - " + row[2];
		
		if(row[3] == 0)
		output = "<em>" + output + "</em>";
		
		return output;
	}

	function formatResult(row){
		return row[1];
	}
	
	

	
	
	
	
   function init_btn_follow(){	   
	$('.btn-follow.follow').html('Follow');
	$('.btn-follow.unfollow').html('Following');
	
   }
   init_btn_follow();
	
  
   
   
	$('.btn-follow.follow').livequery('click',function(){
		// find out what should be followed
		what = $(this).attr('rel');
		
		// change state of this btn
		$(this).addClass('unfollow').removeClass('follow');
		
		init_btn_follow();
		actionFollow(what);
	});
	
	$('.btn-follow.unfollow').livequery('click',function(){
		// find out what should be followed
		what = $(this).attr('rel');

		// change state of this btn
		$(this).addClass('follow').removeClass('unfollow');
		
		init_btn_follow();
		actionUnfollow(what);
	});
	
	$('.btn-follow.unfollow').livequery(function(){
		$(this).hover(
				function(){ $(this).html('Unfollow'); },
				function(){ init_btn_follow(); }
				);
	}, function() { 
        $(this) 
        .unbind('mouseover') 
        .unbind('mouseout'); 
	});
	
	$(document).click(function(){
		if(!$('#cluetip').is(':hidden'))
		$('#cluetip-close').click();
		
		 
	});
	
	$('.notification-bar').animate({ opacity: 1}, 4500).fadeOut();
/*	$('#sponsors').cycle({
		 fx:      'fade', 
         speed:    'slow', 
		 timeout:  6000 

	});
*/
	$(".box-head").prepend('<div class="box-head-right">&nbsp;');
	$(".box-head").append("&nbsp;</div>");
	
	$('a.lang_switch').cluetip({
	cluetipClass: 'jtip', 
	dropShadow: false, 
	dropShadowSteps: 1,
	positionBy: 'fixed',
	closePosition: 'bottom',
	closeText: '',
	activation: 'click',
	width: 85, 
	height: 'auto', // 87
	showTitle: false,
	leftOffset: -85,
	topOffset: 20,
	mouseOutClose: true,
	sticky: true,

	hoverIntent: {
    sensitivity:  3,
    interval:     150,
    timeout:      50    
  	}

	});
/*	
	 $('.btn').each(function(){
	 var b = $(this);
	 var tt = b.text() || b.val();
	 if ($(':submit,:button',this)) {
	 b = $('<a>').insertAfter(this). addClass(this.className).attr('id',this.id);
	 $(this).remove();
	 }
	 b.text('').css({cursor:'pointer'}). prepend('<i></i>').append($('<span>').
	 text(tt).append('<i></i><span></span>'));
	 });
*/
	initAjaxContent();
	
	
});


$(function()
{
	
});

function initAjaxContent(){
	initAname();
}

function initAname(){
	$('a.name').cluetip({
	 	width:            '400',      // The width of the clueTip
	    height:           'auto',   // The height of the clueTip. more info below [1]
	    cluezIndex:       97,       // Sets the z-index style property of the clueTip
	    positionBy:       'auto',   // Sets the type of positioning. more info below [2]
	    topOffset:        15,       // Number of px to offset clueTip from top of invoking element. more info below [3]
	    leftOffset:       15,       // Number of px to offset clueTip from left of invoking element. more info below [4]
	    local:            false,    // Whether to use content from the same page for the clueTip's body
	                                // (treats the attribute used for accessing the tip as a jQuery selector,
	                                // but only selects the first element if the selector matches more than one). more info below [5]
	    hideLocal:        true,     // If local option is set to true, this determines whether local content
	                                //  to be shown in clueTip should be hidden at its original location
	    attribute:        'rel',    // the attribute to be used for fetching the clueTip's body content
	    titleAttribute:   '',  		// the attribute to be used for fetching the clueTip's title
	    splitTitle:       '',       // A character used to split the title attribute into the clueTip title and divs
	                                // within the clueTip body. more info below [6]
	    showTitle:        false,     // show title bar of the clueTip, even if title attribute not set
	    cluetipClass:     'default',// class added to outermost clueTip div in the form of 'cluetip-' + clueTipClass. more info below [7]
	    hoverClass:       '',       // class applied to the invoking element onmouseover and removed onmouseout
	    waitImage:        true,     // whether to show a "loading" img, which is set in jquery.cluetip.css
	    arrows:           false,    // if true, displays arrow on appropriate side of clueTip. more info below [8]
	    dropShadow:       true,     // set to false if you don't want the drop-shadow effect on the clueTip
	    dropShadowSteps:  6,        // adjusts the size of the drop shadow
	    sticky:           true,    // keep visible until manually closed
	    mouseOutClose:    true,    // close when clueTip is moused out
	    activation:       'hover',  // set to 'click' to force user to click to show clueTip
	    clickThrough:     true,    // if true, and activation is not 'click', then clicking on a clueTipped link will take user to 
	                                // the link's href, even if href and tipAttribute are equal
	    tracking:         false,    // if true, clueTip will track mouse movement (experimental)
	    delayedClose:     0,        // close clueTip on a timed delay (experimental)
	    closePosition:    'bottom',    // location of close text for sticky cluetips; can be 'top' or 'bottom' or 'title'
	    closeText:        'Close',  // text (or HTML) to to be clicked to close sticky clueTips
	    truncate:         0,        // number of characters to truncate clueTip's contents. if 0, no truncation occurs

	    // effect and speed for opening clueTips
	    fx: {             
	                      open:       'fadeIn', // can be 'show' or 'slideDown' or 'fadeIn'
	                      openSpeed:  'slow'
	    },
	                  
	    // settings for when hoverIntent plugin is used
	    hoverIntent: {    
	                      sensitivity:  3,
	                      interval:     50,
	                      timeout:      0
	    }, 
	    
	    
	    // whether to cache results of ajax request to avoid unnecessary hits to server
	    ajaxCache:        true,     
	    
	    // can pass in standard $.ajax() parameters, not including error, complete, success, and url
	    ajaxSettings: {   
	                      dataType: 'html'
	    }
								
		});
	
}

function updateInvDiv()
{
	document.getElementById('ownTextPreview').innerHTML=document.getElementById('txtOwnText').value.replace('\n','<br>').replace('\n','<br>').replace('\n','<br>').replace('\n','<br>').replace('\n','<br>').replace('\n','<br>') + '<br><br>---';	
}

function delAngebot(jid)
 {
 	if(confirm("Dieses Angebot wirklich entfernen?"))
	{
		document.location='delAngebot.php?jid='+jid;
	}
 }

function adminDelUser(uID)
{
 	if(confirm("Sind Sie sicher?"))
	{
//		document.location='removeUser.php?u='+uID;
		return true;
	}else
	{
	return false;
	}
}

function delFreundConfirm(uID,uName,profile)
{
 	if(confirm(uName))
	{
		document.location='/contacts/remove.php?u='+uID+'&returntoprofile='+profile;
	}
}

function confirmDelGroup(gID,gName)
{
 	if(confirm("Das Forum '" + gName + "' wirklich entfernen?"))
	{
		document.location='remove.php?grp='+gID;
	}
}


function confirmDelTermin(tID,tName)
{
 	if(confirm("Den Termin '" + tName + "' wirklich absagen?"))
	{
		document.location='remove.php?tid='+tID;
	}
}

function adminSelectAll()
{
	for (var i = 0;i < document.mark.elements.length;i++)
	{
		
			document.mark.elements[i].checked = document.mark.markAll.checked;
		
	}
}

function saveDatenfreigabe(UserID)
{
if (xmlHttp) {
	
	// string aufbereiten
	var datenstring;
	datenstring="";

	if(document.getElementById("dataGMail").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	if(document.getElementById("dataGAdresse").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	if(document.getElementById("dataGTelefon").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	if(document.getElementById("dataGFax").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	
	if(document.getElementById("dataPMail").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	if(document.getElementById("dataPOrt").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	if(document.getElementById("dataPBuLa").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	if(document.getElementById("dataPLand").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	if(document.getElementById("dataPAdresse").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	if(document.getElementById("dataPTelefon").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	if(document.getElementById("dataPFax").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	
	if(document.getElementById("dataIMICQ").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	if(document.getElementById("dataIMMSN").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	if(document.getElementById("dataIMAIM").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	if(document.getElementById("dataIMYahoo").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	if(document.getElementById("dataIMSkype").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	
	if(document.getElementById("dataMobil").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	if(document.getElementById("dataGeb").checked)
	{datenstring+="1,";}else{datenstring+="0,";}
	//if(document.getElementById("dataMSG").checked)
	//{datenstring+="1";}else{datenstring+="0";}
	datenstring+="0";

	
	document.getElementById('dataStatus').innerHTML='<img src="/img/loading_small.gif" />';
    xmlHttp.open('POST', '/ajaxSaveDatenfreigabe.php');
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send('daten='+datenstring+'&uid='+UserID);
	xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
			document.getElementById('dataStatus').innerHTML='<img src="/img/saved_icon.png" />';
			}
		};
	

}
}


function event_invite(user_id,action,event_id)
{
	$.get("/events/invite/ajaxInvite.php", { userid: user_id, action: action, event_id: event_id},
   function(data){

	if(action=='add')
	{
		document.getElementById('u'+user_id).style.display='none';	
		document.getElementById('l'+user_id).style.display='block';	
	}
	
	if(action=='remove')
	{
		document.getElementById('u'+user_id).style.display='block';	
		document.getElementById('l'+user_id).style.display='none';	
	}
	
	
	
	
	 
   });
}

function updateProfilNotes(UserID)
{
if (xmlHttp) {
    xmlHttp.open('POST', '/profil/ajaxUpdateProfilNotes.php');
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send('myNotes='+document.getElementById("idProfilNotes").value+'&uid='+UserID);
	xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
				$('#profilNotesSave').fadeOut();
			}
		};
	

}
}

function switchDataAll()
{
	


		document.getElementById('dataAll').checked=document.getElementById('dataAll').checked;
	
		document.getElementById('dataGAll').checked=document.getElementById('dataAll').checked;
			document.getElementById('dataGMail').checked=document.getElementById('dataAll').checked;
			document.getElementById('dataGAdresse').checked=document.getElementById('dataAll').checked;
			document.getElementById('dataGTelefon').checked=document.getElementById('dataAll').checked;
			document.getElementById('dataGFax').checked=document.getElementById('dataAll').checked;
			
		document.getElementById('dataPAll').checked=document.getElementById('dataAll').checked;
			document.getElementById('dataPMail').checked=document.getElementById('dataAll').checked;
			document.getElementById('dataPOrt').checked=document.getElementById('dataAll').checked;
			document.getElementById('dataPBuLa').checked=document.getElementById('dataAll').checked;
			document.getElementById('dataPLand').checked=document.getElementById('dataAll').checked;
			document.getElementById('dataPAdresse').checked=document.getElementById('dataAll').checked;
			document.getElementById('dataPTelefon').checked=document.getElementById('dataAll').checked;
			document.getElementById('dataPFax').checked=document.getElementById('dataAll').checked;
			
		document.getElementById('dataIMAll').checked=document.getElementById('dataAll').checked;
			document.getElementById('dataIMICQ').checked=document.getElementById('dataAll').checked;
			document.getElementById('dataIMMSN').checked=document.getElementById('dataAll').checked;
			document.getElementById('dataIMAIM').checked=document.getElementById('dataAll').checked;
			document.getElementById('dataIMYahoo').checked=document.getElementById('dataAll').checked;
			document.getElementById('dataIMSkype').checked=document.getElementById('dataAll').checked;
			
		document.getElementById('dataMobil').checked=document.getElementById('dataAll').checked;
		document.getElementById('dataGeb').checked=document.getElementById('dataAll').checked;
		document.getElementById('dataMSG').checked=document.getElementById('dataAll').checked;
}


function switchDataGAll()
{
	


		//document.getElementById('dataAll').checked='';
	
		document.getElementById('dataGAll').checked=document.getElementById('dataGAll').checked;
			document.getElementById('dataGMail').checked=document.getElementById('dataGAll').checked;
			document.getElementById('dataGAdresse').checked=document.getElementById('dataGAll').checked;
			document.getElementById('dataGTelefon').checked=document.getElementById('dataGAll').checked;
			document.getElementById('dataGFax').checked=document.getElementById('dataGAll').checked;
			

}

function toggleIMAll()
{
	if(document.getElementById('boxIMAll').style.display=='none')
	{
//		document.getElementById('boxIMAll').style.display='block';
		$('#boxIMAll').slideDown();
		document.getElementById('toggleIM').innerHTML='<img src="/img/list_minus.png" onclick="toggleIMAll(); return false;" />';
	}else
	{
//		document.getElementById('boxIMAll').style.display='none';
		$('#boxIMAll').slideUp();
		document.getElementById('toggleIM').innerHTML='<img src="/img/list_plus.png" onclick="toggleIMAll(); return false;" />';
	}
	
}

function togglePAll()
{
	if(document.getElementById('boxPAll').style.display=='none')
	{
		//document.getElementById('boxPAll').style.display='block';
		$('#boxPAll').slideDown();
		document.getElementById('toggleP').innerHTML='<img src="/img/list_minus.png" onclick="togglePAll(); return false;" />';
	}else
	{
		//document.getElementById('boxPAll').style.display='none';
		$('#boxPAll').slideUp();
		document.getElementById('toggleP').innerHTML='<img src="/img/list_plus.png" onclick="togglePAll(); return false;" />';
	}
	
}

function toggleGAll()
{
	if(document.getElementById('boxGAll').style.display=='none')
	{
//		document.getElementById('boxGAll').style.display='block';
		$('#boxGAll').slideDown();
		document.getElementById('toggleG').innerHTML='<img src="/img/list_minus.png" onclick="toggleGAll(); return false;" />';
	}else
	{
		//document.getElementById('boxGAll').style.display='none';
		$('#boxGAll').slideUp();
		document.getElementById('toggleG').innerHTML='<img src="/img/list_plus.png" onclick="toggleGAll(); return false;" />';
	}
	
}

function switchDataPAll()
{
	


		//document.getElementById('dataAll').checked='';
	
		document.getElementById('dataPAll').checked=document.getElementById('dataPAll').checked;
			document.getElementById('dataPMail').checked=document.getElementById('dataPAll').checked;
			document.getElementById('dataPOrt').checked=document.getElementById('dataPAll').checked;
			document.getElementById('dataPBuLa').checked=document.getElementById('dataPAll').checked;
			document.getElementById('dataPLand').checked=document.getElementById('dataPAll').checked;
			document.getElementById('dataPAdresse').checked=document.getElementById('dataPAll').checked;
			document.getElementById('dataPTelefon').checked=document.getElementById('dataPAll').checked;
			document.getElementById('dataPFax').checked=document.getElementById('dataPAll').checked;
			

}


function switchDataIMAll()
{
	


		//document.getElementById('dataAll').checked='';
	
	document.getElementById('dataIMAll').checked=document.getElementById('dataIMAll').checked;
			document.getElementById('dataIMICQ').checked=document.getElementById('dataIMAll').checked;
			document.getElementById('dataIMMSN').checked=document.getElementById('dataIMAll').checked;
			document.getElementById('dataIMAIM').checked=document.getElementById('dataIMAll').checked;
			document.getElementById('dataIMYahoo').checked=document.getElementById('dataIMAll').checked;
			document.getElementById('dataIMSkype').checked=document.getElementById('dataIMAll').checked;
			

}


function showProfilKartei(which)
{
	document.getElementById('data1').style.display='none';
	document.getElementById('data2').style.display='none';
	document.getElementById('data3').style.display='none';
	document.getElementById('data4').style.display='none';
	
	document.getElementById('navi1').style.display='none';
	document.getElementById('navi2').style.display='none';
	document.getElementById('navi3').style.display='none';
	document.getElementById('navi4').style.display='none';
	switch(which)
	{
		case "perso":
		document.getElementById('data1').style.display='block';
		document.getElementById('navi1').style.display='block';
		break;
		
		case "kontakt":
		document.getElementById('data2').style.display='block';
		document.getElementById('navi2').style.display='block';
		break;
		
		case "web":
		document.getElementById('data3').style.display='block';
		document.getElementById('navi3').style.display='block';
		break;
		
		case "uber":
		document.getElementById('data4').style.display='block';
		document.getElementById('navi4').style.display='block';
		break;
	}
}

function selectAll()
{
	for (var i = 0;i < document.mark.elements.length;i++)
	{
		
			document.mark.elements[i].checked = document.mark.markAll.checked;
		
	}
}

function newsletter_test(id)
{
	$.get("/manage/_ajax_newsletter_test.php", { nid: id},
   function(data){
	alert(data);
	alert("Testmail generated. Should be sent within the next 10 minutes.");
   });
	
}



// overlay

