// Konfigs
var Config=new Array();
var InfoIDs=new Array();
var HiddenID=new Array();
var OldInfoID=0;
Config['uri']='/mib/';
Config['db']='mysql';
Config['tf']='';


//Homebase
function HBTitelToggle(ID,CloseID){
	if(CloseID!=0){
		document.getElementById("HB"+CloseID).style.display = "none";
	}else{
		document.getElementById("HB"+ID).style.display = "";
	}
}


//Pm System
var PMFrendListOut='';
var PMFrendSelectetOut='';
var SelectedPMContact=0;
var StopSelection=0;
function CreatePMFrendlist(SelectedID,FixedID){
	size=MyFrends.length;
	for(i=1;i<size;i++){
		PMFrendListOut+='<div id="CID'+i+'" style="padding:2px;height:20px;background-color:#ffffff;border:1px solid #157a92;margin-left:3px;margin-top:3px;color:#157a92;font-weight:600;" onclick="SelectContact('+i+',0)" onmouseover="ChangeBGContacts('+i+',0);this.style.cursor=\'pointer\';" onmouseout="ChangeBGContacts(0,'+i+')">';
		PMFrendListOut+=MyFrends[i]['Name']+' ';
		PMFrendListOut+='</div>';
		if(MyFrends[i]['ID']==FixedID||MyFrends[i]['ID']==SelectedID){
			FixedIDi=i;
		}
	}
	document.getElementById('Contacts').innerHTML = PMFrendListOut;
	if(FixedID>0||SelectedID>0){
		SelectContact(FixedIDi,FixedID);
	}
}

function ChangeBGContacts(CID,CoutID){
	if(StopSelection==0){
		if(CID!=0){
			document.getElementById("CID"+CID).style.backgroundColor = "#157a92";
			document.getElementById("CID"+CID).style.color = "#FFFFFF";
		}else if(CoutID!=SelectedPMContact){
			document.getElementById("CID"+CoutID).style.backgroundColor = "#ffffff";
			document.getElementById("CID"+CoutID).style.color = "#157a92";
		}
	}
}

function SelectContact(CID,FixedID){
	if(StopSelection==0){
		PMFrendSelectetOut='<img src="'+MyFrends[CID]['PImage']+'" alt="'+MyFrends[CID]['Name']+'" />';
		document.getElementById('UserImage').innerHTML = PMFrendSelectetOut;
		document.getElementById("sendingto").value = MyFrends[CID]['ID'];

		if(SelectedPMContact!=CID&&SelectedPMContact!=0){
			document.getElementById("CID"+SelectedPMContact).style.backgroundColor = "#ffffff";
			document.getElementById("CID"+SelectedPMContact).style.color = "#157a92";
		}

		document.getElementById("CID"+CID).style.backgroundColor = "#157a92";
		document.getElementById("CID"+CID).style.color = "#FFFFFF";

		SelectedPMContact=CID;
		if(FixedID>0){
			StopSelection=1;
		}
	}
}

// Multi Uploader
var AllImageCount=0;
var InProgressUpload=0;
function StartUpload(){
	document.getElementById("SiteOverlay").style.display = '';
	document.getElementById('uploadDetails').innerHTML = '0 von '+AllImageCount+' hochgeladen.';
	document.getElementById("UploadeStartOut").style.display = '';
	$('#SelectImages').uploadifyUpload();
};


//Kampagnen - Homebase
var OldCSelectionType=0;
function CampaignFiltering(){
	for (i = 0; i < document.Campaigns.filter.length; ++i){
		if (document.Campaigns.filter.options[i].selected == true){
			ID=document.Campaigns.filter.options[i].value;
		}
	}

	Types=new Array(1,2,3);
	for(c=0;c<Types.length;c++){

		size=document.getElementsByName('C'+ID).length;
		for(i=0;i<size;i++){
			document.getElementsByName('C'+ID)[i].style.display = '';
		}

		if(Types[c]!=ID&&ID!=0){
			size=document.getElementsByName('C'+Types[c]).length;
			for(i=0;i<size;i++){
				document.getElementsByName('C'+Types[c])[i].style.display = 'none';
			}
		}else{
			size=document.getElementsByName('C'+Types[c]).length;
			for(i=0;i<size;i++){
				document.getElementsByName('C'+Types[c])[i].style.display = '';
			}
		}
	}

}


// AJAX
var GSAXDate =getXMLRequest();
function getXMLRequest(){
	try{
		return new XMLHttpRequest();
	}
	catch (ms){
		try{
			return new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (nonms){
			try{
				return new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed){
				return null;
			}
		}
	}
}


//Info-Nav. Monitoring
var inTime;
var OldFrendsOnline=0;
var StartFrendCheck=0;
var FIDs="";
var OldFrendsOnlineIDs="";
var sendMoData =getXMLRequest();
var OldNavUserID=0;
var InfoUserIDs=new Array();
function inMonitoring(){
	if (FIDs!="") {
		clearInterval(inTime);
		sendMoData.open("POST", Config['uri']+'module/'+Config['db']+'/monitoring/monitoring.php?s='+StartFrendCheck+'&ofo='+OldFrendsOnline, true);
		sendMoData.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		sendMoData.onreadystatechange = function(){
			switch(sendMoData.readyState){
				case 4:
					InputString=sendMoData.responseText;
					if(sendMoData.responseText!=""){
						InputString=InputString.split(';;');
						document.getElementById('Frendsonline').innerHTML=InputString[0];

						if(InputString[2]!=''){
							Infobox=InputString[2].replace(/{uri}/g,Config['uri']);
							Infobox=Infobox.replace(/{tf}/g,Config['tf']);
							document.getElementById('InfoShortBox').innerHTML+=Infobox;
						}

						if(InputString[3]!=''){
							FOnlineNav=InputString[3].replace(/{uri}/g,Config['uri']);
							FOnlineNav=FOnlineNav.replace(/{tf}/g,Config['tf']);
							document.getElementById('i101').innerHTML=FOnlineNav;
						}else{
							document.getElementById('i101').innerHTML="Es sind keine Freunde online";
						}

						//JS Vars Upgraden
						if(StartFrendCheck==0){StartFrendCheck=1;}
						OldFrendsOnline=InputString[0];
						OldFrendsOnlineIDs=InputString[1];

					}
					inTime = setTimeout('inMonitoring();',2000);
				break;
				default:
					return false;
				break;
			}
		};
		var parameters='FIDs='+FIDs+'&ois='+OldFrendsOnlineIDs;
		sendMoData.setRequestHeader("Content-length", parameters.length);
		sendMoData.setRequestHeader("Connection", "close");
		sendMoData.send(parameters);
	}else{
		document.getElementById('Frendsonline').innerHTML=0;
		document.getElementById('i101').innerHTML="Es sind keine Freunde online";
	}
}

function NavToggle(ID){
	if(OldNavUserID!=0&&OldNavUserID!=ID){
		document.getElementById("u"+OldNavUserID).style.display = "none";
		InfoUserIDs[OldNavUserID]=0;
	}
	if(InfoUserIDs[ID]==0||InfoUserIDs[ID]==undefined){
		document.getElementById("u"+ID).style.display = "";
		InfoUserIDs[ID]=1;
		OldNavUserID=ID;
	}else{
		document.getElementById("u"+ID).style.display = "none";
		InfoUserIDs[ID]=0;
		OldNavUserID=0;
	}


}


// Chat Monitoring
var cTime;
function ChatMonitoring(){
	if (GSAXDate.readyState == 4 || GSAXDate.readyState == 0) {
		GSAXDate.open("GET", Config['uri']+'module/'+Config['db']+'/chat/chatmonitoring.php', true);
		GSAXDate.onreadystatechange = function(){
			switch(GSAXDate.readyState){
				case 4:
					if(GSAXDate.responseText!=""){
						clearInterval(cTime);
						InputString=GSAXDate.responseText;
						InputString=InputString.split(';');
						buildM='<div style="float:left;width:140px;">';
						buildM+='<img src="'+InputString[3]+'" alt="'+InputString[2]+'" />';
						buildM+='</div><div style="float:left;">';
						buildM+='<b>'+InputString[2]+'</b> hat dich zum chatten eingeladen.<br />';
						buildM+='<div onclick="ChatInvitation(1,'+InputString[0]+');javascript:void(window.open(\''+Config['uri']+'chat.php?ContactID='+InputString[1]+'&SessionID='+InputString[0]+'\',\'Chat'+InputString[1]+'\',\'toolbar=no,width=550,height=600,resizable=no,scrollbars=no\'));" style="margin-top:93px;float:left;width:100px;border:2px solid #610000;height:40px;text-align:center;line-height:35px;" class="button" onmouseover="this.style.cursor=\'pointer\'">annehmen</div>';
						buildM+='<div onclick="ChatInvitation(2,'+InputString[0]+');" style="margin-left:20px;margin-top:93px;float:left;width:100px;border:2px solid #610000;height:40px;text-align:center;line-height:35px;" class="button" onmouseover="this.style.cursor=\'pointer\'">ablehnen</div>';
						buildM+='</div>';
						buildM+='<div class="clear"></div>';
						document.getElementById('InvitationDetails').innerHTML=buildM;
						document.getElementById("SiteOverlay").style.display = '';
						document.getElementById("ChatInvitation").style.display = '';

					}else{
						cTime = setTimeout('ChatMonitoring();',2000);
					}
				break;
				default:
					return false;
				break;
			}
		};
		GSAXDate.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		GSAXDate.send(null);
	}
}

function ChatInvitation(Type,SessionID){
	if (GSAXDate.readyState == 4 || GSAXDate.readyState == 0) {
		GSAXDate.open("GET", Config['uri']+'module/'+Config['db']+'/chat/senditype.php?t='+Type+'&s='+SessionID, true);
		GSAXDate.onreadystatechange = function(){
			switch(GSAXDate.readyState){
				case 4:
					document.getElementById("SiteOverlay").style.display = 'none';
					document.getElementById("ChatInvitation").style.display = 'none';
					cTime = setTimeout('ChatMonitoring();',2000);
				break;
				default:
					return false;
				break;
			}
		};
		GSAXDate.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		GSAXDate.send(null);
	}
}


//Allgemeine JS/Funktionen
function InfoToggle(ID,HidenSite,OnlyClose){
	if(OnlyClose==0){
		if(OldInfoID!=0&&OldInfoID!=ID){
			document.getElementById("i"+OldInfoID).style.display = "none";
			InfoIDs[OldInfoID]=0;
		}
		if(InfoIDs[ID]==0||InfoIDs[ID]==undefined){
			document.getElementById("i"+ID).style.display = "";
			InfoIDs[ID]=1;
			OldInfoID=ID;
		}else{
			document.getElementById("i"+ID).style.display = "none";
			InfoIDs[ID]=0;
			OldInfoID=0;
		}
		if(HidenSite==1){
			if(HiddenID[ID]==0||HiddenID[ID]==undefined){
				document.getElementById("SiteOverlay").style.display = "";
				HiddenID[ID]=1;
			}else{
				document.getElementById("SiteOverlay").style.display = "none";
				HiddenID[ID]=0;
			}
		}
	}else{
		document.getElementById(OnlyClose).style.display = "none";
	}

}
