
// 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();
}


var IE = document.all?true:false


function arrangePic(picid)
{

if (xmlHttp) {
    xmlHttp.open('POST', 'http://www.cruisr.de/gallery/ajaxSet2Album.php');
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send('newAlbum='+document.getElementById("chgAlbum"+picid).value+'&picid='+picid);
	xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {

//			redrawGroups();
			document.getElementById('changePicDiv'+picid).style.display='none';
			document.getElementById('pic'+picid).style.filter="Alpha(opacity=10)";
			document.getElementById('pic'+picid).style.MozOpacity = .10;

			}
		};
	//document.getElementById("gruppe"+BuddyID).style.display = 'block';
	//document.getElementById("chgTextU"+BuddyID).style.display = 'block';
	//document.getElementById("chgGrpU"+BuddyID).style.display = 'none';
	//document.getElementById("gruppe"+BuddyID).innerHTML = document.getElementById("setNewGrpU"+BuddyID).options[document.getElementById("setNewGrpU"+BuddyID).selectedIndex].text;

}
}

function voteForUser(userid)
{

 if (xmlHttp) {
     xmlHttp.open('GET', 'http://www.cruisr.de/vote/vote.php?score='+document.getElementById("voteScore").value+'&uid='+userid, true);
     xmlHttp.onreadystatechange = function () {
         if (xmlHttp.readyState == 4) {
			document.getElementById('justVoted').style.display='block';
			document.getElementById('newVote').style.display='none';
         }
     };
     xmlHttp.send(null);
 }

}


function FlashMovie(src, movie, width, height, version, quality, menu, bgcolor, flashvars)
{
	document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+version+",0,0,0' width='" +width+ "' height='" +height+ "' id='" +movie+ "'>");
	document.write("<param name='movie' value='" +src+ "' />");
	document.write("<param name='FlashVars' value='" +flashvars+ "'>");
	document.write("<param name='quality' value='" +quality+ "' />");
	document.write("<param name='wmode' value='transparent' />");
	document.write("<param name='menu' value='" +menu+ "' />");
	document.write("<param name='bgcolor' value='" +bgcolor+ "' />");
	document.write("<embed src='" +src+ "' swLiveConnect='true' menu='" +menu+ "' FlashVars='" +flashvars+ "' quality='" +quality+ "' bgcolor='" +bgcolor+ "' width='" +width+ "' height='" +height+ "' name='" +movie+ "' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
	document.write("</object>");
}


function delAccount()
 {
 	if(confirm("Deine Mitgliedschaft wirklich beenden?"))
	{
		document.location='delAccount.php';
	}
 }

function updateInvDiv()
{
	document.getElementById('ownTextPreview').innerHTML=document.getElementById('txtOwnText').value + '<br><br>---';
}

function showUp(evt) {

	myPS= Math.ceil(document.getElementById('pAutopower').value * 1.36);
	document.getElementById('pAutopowerPS').value = myPS;
	//document.divMyPS.write(myPS);
	//alert(myPS);
}

function showUpPS(evt) {

	myKW= Math.ceil(document.getElementById('pAutopowerPS').value * 0.74);
	document.getElementById('pAutopower').value = myKW;
	//document.divMyPS.write(myPS);
	//alert(myPS);
}


function deleteSentMessage(PmID)
{
	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.cruisr.de/messaging/ajaxDelSentMessage.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttp.send('pmid='+PmID);

		document.getElementById('delPM'+PmID).style.display='none';
	}
}

function setNewGroup(BuddyID)
{
if (xmlHttp) {
    xmlHttp.open('POST', 'http://www.cruisr.de/contacts/ajaxSetNewGroup.php');
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send('newGrp='+document.getElementById("setNewGrpU"+BuddyID).value+'&buddyid='+BuddyID);
	xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {

		//	redrawGroups();

			}
		};
	document.getElementById("gruppe"+BuddyID).style.display = 'block';
	document.getElementById("chgTextU"+BuddyID).style.display = 'block';
	document.getElementById("chgGrpU"+BuddyID).style.display = 'none';
	document.getElementById("gruppe"+BuddyID).innerHTML = document.getElementById("setNewGrpU"+BuddyID).options[document.getElementById("setNewGrpU"+BuddyID).selectedIndex].text;

}
}


function changeUseHistory()
{
if (xmlHttp) {
    xmlHttp.open('POST', 'http://www.cruisr.de/you/ajaxChangeUseHistory.php');
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send('useHistory='+document.getElementById("valUseHistory").value);
	xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
				document.getElementById('historyOpt').style.display='none';
			}
		};


}
}

function updateGrpNote(GrpID)
{
if (xmlHttp) {
    xmlHttp.open('POST', 'http://www.cruisr.de/contacts/ajaxUpdateGroupNote.php');
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send('newNote='+document.getElementById("editNoteText").value+'&grpid='+GrpID);
	xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {

		//	redrawGroups();
			document.getElementById('curNote').style.display='block';
			document.getElementById('editNote').style.display='none';
			document.getElementById('curNote').innerHTML=document.getElementById("editNoteText").value;
			}
		};


}
}

function getGroups(BuddyID)
{

 if (xmlHttp) {
     xmlHttp.open('GET', 'http://www.cruisr.de/contacts/ajaxGetGroups.php?buddyid='+BuddyID, true);
     xmlHttp.onreadystatechange = function () {
         if (xmlHttp.readyState == 4) {

			document.getElementById("chgGrpU"+BuddyID).style.display = 'block';
			 document.getElementById("chgGrpU"+BuddyID).innerHTML = xmlHttp.responseText;
			 document.getElementById("gruppe"+BuddyID).style.display = 'none';
			 document.getElementById("chgTextU"+BuddyID).style.display = 'none';
         }
     };
     xmlHttp.send(null);
 }
}

function rejectBuddy(uid)
{

	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.cruisr.de/you/ajaxRejectBuddy.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

		xmlHttp.send('uid='+uid);

		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {

			document.getElementById('cnfmBuddy'+uid).style.display='none';

			}
		};


//		document.getElementById('txtMessage').blur();

	}
}



function confirmBuddy(uid)
{

	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.cruisr.de/you/ajaxSaveBuddy.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

		xmlHttp.send('uid='+uid);

		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {

			document.getElementById('cnfmBuddy'+uid).style.display='none';

			}
		};


//		document.getElementById('txtMessage').blur();

	}
}

function showPicBox()
{
		document.getElementById('picicon').style.display='none';
        document.getElementById('smil').style.display='none';
		document.getElementById('picbox').style.display='block';
		$('#picbox').load('http://www.cruisr.de/you/ajaxPicBox.php');
}

function addPic(id)
{
		$('#picarea').load('http://www.cruisr.de/you/ajaxPicArea.php?id=' + id);
}

function hidePicBox()
{
		document.getElementById('picicon').style.display='block';
        document.getElementById('smil').style.display='block';
		document.getElementById('picbox').style.display='none';
}

function hideBox(which)
{
	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.cruisr.de/ajaxSwitchBoxDsp.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');


		switch(which)
		{
            case "boxengasse":
			document.getElementById('boxBoxengasse').style.display='none';
			document.getElementById('boxBoxengasseHide').style.display='block';
			xmlHttp.send('which=boxengasse');
			break;

            case "FEINL":
			document.getElementById('boxFEINL').style.display='none';
			document.getElementById('boxFEINLHide').style.display='block';
			xmlHttp.send('which=feinl');
			break;

            case "suche":
			document.getElementById('boxSuche').style.display='none';
			document.getElementById('boxSucheHide').style.display='block';
			xmlHttp.send('which=suche');
			break;

			case "freunde":
			document.getElementById('boxFreunde').style.display='none';
			document.getElementById('boxFreundeHide').style.display='block';
			xmlHttp.send('which=profilFreunde');
			break;

			case "recent":
			document.getElementById('boxRecent').style.display='none';
			document.getElementById('boxRecentHide').style.display='block';
			xmlHttp.send('which=profilRecent');
			break;

			case "gbook":
			document.getElementById('boxGBook').style.display='none';
			document.getElementById('boxGBookHide').style.display='block';
			xmlHttp.send('which=profilGBook');
			break;

			case "gruppen":
			document.getElementById('boxGruppen').style.display='none';
			document.getElementById('boxGruppenHide').style.display='block';
			xmlHttp.send('which=profilGruppen');
			break;

			case "history":
			document.getElementById('boxHistory').style.display='none';
			document.getElementById('boxHistoryHide').style.display='block';
			xmlHttp.send('which=startHistory');
			break;

			case "neuebilder":
			document.getElementById('boxNeueBilder').style.display='none';
			document.getElementById('boxNeueBilderHide').style.display='block';
			xmlHttp.send('which=bilderNeue');
			break;

			case "kds":
			document.getElementById('boxKDS').style.display='none';
			document.getElementById('boxKDSHide').style.display='block';
			xmlHttp.send('which=startKDS');
			break;

			case "statistik":
			document.getElementById('boxStatistik').style.display='none';
			document.getElementById('boxStatistikHide').style.display='block';
			xmlHttp.send('which=startStatistik');
			break;

			case "buddynews":
			document.getElementById('boxBuddyNews').style.display='none';
			document.getElementById('boxBuddyNewsHide').style.display='block';
			xmlHttp.send('which=startBuddyNews');
			break;

			case "albenfreunde":
			document.getElementById('boxAlbenFreunde').style.display='none';
			document.getElementById('boxAlbenFreundeHide').style.display='block';
			xmlHttp.send('which=bilderAlbenFreunde');
			break;

			case "bildermark":
			document.getElementById('boxBilderMark').style.display='none';
			document.getElementById('boxBilderMarkHide').style.display='block';
			xmlHttp.send('which=bilderMarkierungen');
			break;

			case "nachrichtenverlauf":
			document.getElementById('boxNachrichtenVerlauf').style.display='none';
			document.getElementById('boxNachrichtenVerlaufHide').style.display='block';
			xmlHttp.send('which=nachrichtVerlauf');
			break;

			case "wand":
			document.getElementById('boxWand').style.display='none';
			document.getElementById('boxWandHide').style.display='block';
			xmlHttp.send('which=kreiseWand');
			break;

			case "wiw":
			document.getElementById('boxWIW').style.display='none';
			document.getElementById('boxWIWHide').style.display='block';
			xmlHttp.send('which=kreiseWIW');
			break;

			case "wio":
			document.getElementById('boxWIO').style.display='none';
			document.getElementById('boxWIOHide').style.display='block';
			xmlHttp.send('which=wio');
			break;

			case "neuimkreis":
			document.getElementById('boxNIK').style.display='none';
			document.getElementById('boxNIKHide').style.display='block';
			xmlHttp.send('which=kreiseNeu');
			break;

			case "car":
			document.getElementById('boxCar').style.display='none';
			document.getElementById('boxCarHide').style.display='block';
			xmlHttp.send('which=profilCar');
			break;

			case "interessen":
			document.getElementById('boxInteressen').style.display='none';
			document.getElementById('boxInteressenHide').style.display='block';
			xmlHttp.send('which=profilInteressen');
			break;

			case "personal":
			document.getElementById('boxPersonal').style.display='none';
			document.getElementById('boxPersonalHide').style.display='block';
			xmlHttp.send('which=profilPersonal');
			break;

			case "palben":
			document.getElementById('boxPAlben').style.display='none';
			document.getElementById('boxPAlbenHide').style.display='block';
			xmlHttp.send('which=profilAlben');
			break;

		}

	}

}

function showBox(which)
{
	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.cruisr.de/ajaxSwitchBoxDsp.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');


		switch(which)
		{
			case "boxengasse":
			document.getElementById('boxBoxengasse').style.display='block';
			document.getElementById('boxBoxengasseHide').style.display='none';
			xmlHttp.send('which=boxengasse');
			break;

            case "FEINL":
			document.getElementById('boxFEINL').style.display='block';
			document.getElementById('boxFEINLHide').style.display='none';
			xmlHttp.send('which=feinl');
			break;

            case "suche":
			document.getElementById('boxSuche').style.display='block';
			document.getElementById('boxSucheHide').style.display='none';
			xmlHttp.send('which=suche');
			break;

			case "freunde":
			document.getElementById('boxFreunde').style.display='block';
			document.getElementById('boxFreundeHide').style.display='none';
			xmlHttp.send('which=profilFreunde');
			break;

			case "recent":
			document.getElementById('boxRecent').style.display='block';
			document.getElementById('boxRecentHide').style.display='none';
			xmlHttp.send('which=profilRecent');
			break;

			case "gbook":
			document.getElementById('boxGBook').style.display='block';
			document.getElementById('boxGBookHide').style.display='none';
			xmlHttp.send('which=profilGBook');
			break;

			case "gruppen":
			document.getElementById('boxGruppen').style.display='block';
			document.getElementById('boxGruppenHide').style.display='none';
			xmlHttp.send('which=profilGruppen');
			break;

			case "history":
			document.getElementById('boxHistory').style.display='block';
			document.getElementById('boxHistoryHide').style.display='none';
			xmlHttp.send('which=startHistory');
			break;

			case "neuebilder":
			document.getElementById('boxNeueBilder').style.display='block';
			document.getElementById('boxNeueBilderHide').style.display='none';
			xmlHttp.send('which=bilderNeue');
			break;

			case "kds":
			document.getElementById('boxKDS').style.display='block';
			document.getElementById('boxKDSHide').style.display='none';
			xmlHttp.send('which=startKDS');
			break;

			case "statistik":
			document.getElementById('boxStatistik').style.display='block';
			document.getElementById('boxStatistikHide').style.display='none';
			xmlHttp.send('which=startStatistik');
			break;

			case "buddynews":
			document.getElementById('boxBuddyNews').style.display='block';
			document.getElementById('boxBuddyNewsHide').style.display='none';
			xmlHttp.send('which=startBuddyNews');
			break;

			case "albenfreunde":
			document.getElementById('boxAlbenFreunde').style.display='block';
			document.getElementById('boxAlbenFreundeHide').style.display='none';
			xmlHttp.send('which=bilderAlbenFreunde');
			break;

			case "bildermark":
			document.getElementById('boxBilderMark').style.display='block';
			document.getElementById('boxBilderMarkHide').style.display='none';
			xmlHttp.send('which=bilderMarkierungen');
			break;

			case "nachrichtenverlauf":
			document.getElementById('boxNachrichtenVerlauf').style.display='block';
			document.getElementById('boxNachrichtenVerlaufHide').style.display='none';
			xmlHttp.send('which=nachrichtVerlauf');
			break;

			case "wand":
			document.getElementById('boxWand').style.display='block';
			document.getElementById('boxWandHide').style.display='none';
			xmlHttp.send('which=kreiseWand');
			break;

            case "wiw":
			document.getElementById('boxWIW').style.display='block';
			document.getElementById('boxWIWHide').style.display='none';
			xmlHttp.send('which=kreiseWIW');
			break;

            case "wio":
			document.getElementById('boxWIO').style.display='block';
			document.getElementById('boxWIOHide').style.display='none';
			xmlHttp.send('which=wio');
			break;

			case "neuimkreis":
			document.getElementById('boxNIK').style.display='block';
			document.getElementById('boxNIKHide').style.display='none';
			xmlHttp.send('which=kreiseNeu');
			break;

			case "car":
			document.getElementById('boxCar').style.display='block';
			document.getElementById('boxCarHide').style.display='none';
			xmlHttp.send('which=profilCar');
			break;

			case "interessen":
			document.getElementById('boxInteressen').style.display='block';
			document.getElementById('boxInteressenHide').style.display='none';
			xmlHttp.send('which=profilInteressen');
			break;

			case "personal":
			document.getElementById('boxPersonal').style.display='block';
			document.getElementById('boxPersonalHide').style.display='none';
			xmlHttp.send('which=profilPersonal');
			break;

			case "palben":
			document.getElementById('boxPAlben').style.display='block';
			document.getElementById('boxPAlbenHide').style.display='none';
			xmlHttp.send('which=profilAlben');
			break;
		}

	}
}

function get_pos (o)
{
    var pos = { top:0, left:0 };
    if(!o) return pos;
    else if(typeof o == 'string' ) o = document.getElementById(o);

    if( typeof o != 'object'  || typeof o.offsetTop == 'undefined') return pos;
    while (o && o.tagName != 'BODY')
    {
        pos.top  += parseInt( o.offsetTop );
        pos.left += parseInt( o.offsetLeft );
        o = o.offsetParent;
    }
    return pos;
}

function enableMarkMode()
{
	document.getElementById('markMode').value='1';
	document.getElementById('myPic').style.border='2px solid #cc3300';
	document.getElementById('markModeOpt').style.display='block';
	document.getElementById('myPic').style.cursor='crosshair';
}

function disableMarkMode()
{
	document.getElementById('markMode').value='0';
	document.getElementById('myPic').style.border='2px solid #ffffff';
	document.getElementById('markModeOpt').style.display='none';
	document.getElementById('markWho').style.display='none';
	document.getElementById('myPic').style.cursor='default';
}

function showMarker(mid,markIDarray)
{
	showAllMarkers();
	// alle marker ausblenden
//	myMarkerArr = document.getElementById('markIDarray').value.split(",");
	myMarkerArr = markIDarray.split(",");

	for(i=0; i<(myMarkerArr.length-1); i++)
	{
		if(mid!=myMarkerArr[i])
		hideWmarker(myMarkerArr[i]);
	}
	document.getElementById('marker'+mid).style.display='block';
}

function hideMarker(mid, markIDarray)
{
	//myMarkerArr = document.getElementById('markIDarray').value.split(",");
	myMarkerArr = markIDarray.split(",");
	for(i=0; i<(myMarkerArr.length-1); i++)
	{
		showWmarker(myMarkerArr[i]);
	}
	document.getElementById('marker'+mid).style.display='none';
	hideAllMarkers();
}

function hideWmarker(mid)
{
	document.getElementById('wMarker'+mid).style.display='none';
}

function showWmarker(mid)
{
	document.getElementById('wMarker'+mid).style.display='block';
}

function showAllMarkers()
{
	//alert(document.getElementById('myPic').height);
//	document.getElementById('allMarkers').style.width=document.getElementById('myPic').width;
//	document.getElementById('allMarkers').style.height=document.getElementById('myPic').height;
	document.getElementById('allMarkers').style.display='block';
//	alert(document.getElementById('allMarkers').style.getAttribute("height", false);
}

function hideAllMarkers()
{
	document.getElementById('allMarkers').style.display='none';
}

function setMark(uid,picid)
{
	//alert('Setze: x='+document.getElementById('markX').value+' , y='+document.getElementById('markY').value);
	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.cruisr.de/profil/photoalbum/ajaxSetMark.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttp.send('uid='+uid+'&picid='+picid+'&markX='+document.getElementById('markX').value+'&markY='+document.getElementById('markY').value);


		xmlHttp.onreadystatechange = function () {
         if (xmlHttp.readyState == 4) {
			document.getElementById('markWho').style.display='none';

			// neuen marker dynamisch setzen
			document.getElementById('allMarkers').innerHTML=xmlHttp.responseText;
			setTimeout(showAllMarkers(),1000);
         }
     };

	}
}

function getMark(o,e,picid)
{
	var koordArr;
	if(document.getElementById('markMode').value=='1')
	{

		koordArr = koordinaten(o, e);

		koordArr = koordArr.split(",");
		var p = mouse_pos(e);
		loadBuddiesToMark(picid);
		document.getElementById('markWho').style.display='block';
		document.getElementById('markWho').style.left=p.left+'px';
		document.getElementById('markWho').style.top=p.top+'px';

		document.getElementById('markX').value=koordArr[0];
		document.getElementById('markY').value=koordArr[1];

		//alert('Finde: x='+koordArr[0]+' , y='+koordArr[1]);

//		alert(document.getElementById('markWho').top + "," + document.getElementById('markWho').left);
	}
}

function loadBuddiesToMark(picid)
{

 if (xmlHttp) {
     xmlHttp.open('GET', 'http://www.cruisr.de/profil/photoalbum/ajaxGetBuddiesToMark.php?picid='+picid, true);
     xmlHttp.onreadystatechange = function () {
         if (xmlHttp.readyState == 4) {
			document.getElementById('markWho').innerHTML= xmlHttp.responseText;
         }
     };
     xmlHttp.send(null);
 }
}

function mouse_pos(evt)
{
    if(!evt) evt = window.event;
    var pos = {left: evt.clientX, top: evt.clientY};
    var body = (window.document.compatMode && window.document.compatMode == "CSS1Compat") ?
    window.document.documentElement : window.document.body || null;
    if (body)
    {
        pos.left += body.scrollLeft;
        pos.top += body.scrollTop;
    }
    return pos;
}


function koordinaten(el, evt) {
	if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.offsetX + document.getElementById('myPic').scrollLeft
    tempY = event.offsetY + document.getElementById('myPic').scrollTop

  } else {  // grab the x-y pos.s if browser is NS
    var m = mouse_pos(evt);
    var p = get_pos(el);
//   document.Show.BildX.value = (m.left - p.left);
//    document.Show.BildY.value = (m.top - p.top);
	tempX = m.left - p.left;
	tempY = m.top - p.top;
   }

  //  alert(tempX);
  //  alert(tempY);
	return tempX+","+tempY;
}

function delFreundConfirm(uID,uName)
{
 	if(confirm(uName + " wirklich entfernen?"))
	{
		document.location='http://www.cruisr.de/contacts/remove.php?u='+uID;
	}
}

function delPicConfirm(pID)
{
 	if(confirm("Dieses Bild wirklich entfernen?"))
	{
		document.location='http://www.cruisr.de/gallery/delPic.php?picid='+pID;
	}
}

function delAlbumConfirm(aID)
{
 	if(confirm("Dieses Album und seinen gesamten Inhalt wirklich entfernen?"))
	{
		document.location='http://www.cruisr.de/gallery/delAlbum.php?aid='+aID;
	}
}

function leaveGrpConfirm(gID)
{
 	if(confirm("Dieses Gruppe wirklich verlassen?"))
	{
		document.location='http://www.cruisr.de/groups/leave.php?gid='+gID;
	}
}

function setAsRead(PmID)
{
	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.cruisr.de/messaging/ajaxSetAsRead.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttp.send('PmID='+PmID);

	}
}



function sendNewMessage(recvID)
{
	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.cruisr.de/messaging/ajaxSaveNewPM.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttp.send('myText='+escape(document.getElementById("txtMessage").value)+'&myEmpfaenger='+recvID+'&mySubject='+escape(document.getElementById("txtSubject").value));

		document.getElementById('confirmSentDiv').style.display='block';
		document.getElementById('newMessageDiv').style.display='none';
		document.getElementById('txtMessage').blur();

	}
}


function replyMessage(PmID,txtSubject,recvID)
{

if (xmlHttp) {

	xmlHttp.open('POST', 'http://www.cruisr.de/messaging/setdata.php');
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send('PmID='+PmID+'&myText='+escape(document.getElementById("txtAnswer"+PmID).value)+'&myEmpfaenger='+recvID+'&mySubject='+escape(txtSubject));


	xmlHttp.onreadystatechange = function () {
         if (xmlHttp.readyState == 4) {

		// nun noch die Antwortzeit auf der Seite eintragen
		document.getElementById("pmStatus"+PmID).innerHTML = '<div style="margin-top: 4px; font-size: 10px; color: #999999;">Zuletzt beantwortet:</div>vor 1 Minute';
		document.getElementById('pmAnswer'+PmID).style.display='none';
		document.getElementById('txtAnswer'+PmID).value='';

         }
     };

}
}

function deleteMessage(PmID)
{
	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.cruisr.de/messaging/ajaxDelMessage.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttp.send('pmid='+PmID);

		document.getElementById('delPM'+PmID).style.display='none';
	}
}

function sendGreeting(recvID)
{

	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.cruisr.de/profil/ajaxSendGreetings.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttp.send('myEmpfaenger='+recvID);


		xmlHttp.onreadystatechange = function () {
         if (xmlHttp.readyState == 4) {


		alert('Dein Gruss wurde gesendet');

         }
     };

	}
}

function savePicComment(picID)
{

if (xmlHttp) {
    xmlHttp.open('POST', 'http://www.cruisr.de/profil/photoalbum/ajaxSaveComment.php');
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	xmlHttp.send('text='+escape(document.getElementById("commentText").value)+'&picid='+picID);

	document.getElementById('newComment').style.display='none';
	document.getElementById('showNewEintrag').style.display='block';
	document.getElementById('newEintragText').innerHTML=document.getElementById("commentText").value;
//	document.getElementById('curComment'+eintragID).innerHTML=document.getElementById("commentText"+eintragID).value;

}
}



function saveGBEintrag(profilID)
{

if (xmlHttp) {
    xmlHttp.open('POST', 'http://www.cruisr.de/profil/gbook/ajaxSaveEintrag.php');
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	xmlHttp.send('text='+escape(document.getElementById("txtGBook").value)+'&profilid='+profilID);

//	document.getElementById('writeNewEintrag').style.display='none';
	document.getElementById('schreiben').style.display='none';
	document.getElementById('showNewEintrag').style.display='block';
	document.getElementById('newEintragText').innerHTML=document.getElementById("txtGBook").value;

}
}

function saveWandEintrag(kreis)
{

if (xmlHttp) {
    xmlHttp.open('POST', 'http://www.cruisr.de/kreise/wand/ajaxSaveEintrag.php');
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	xmlHttp.send('text='+escape(document.getElementById("txtWand").value)+'&kreis='+kreis);

//	document.getElementById('writeNewEintrag').style.display='none';
	document.getElementById('schreiben').style.display='none';
	document.getElementById('showNewEintrag').style.display='block';
	document.getElementById('newEintragText').innerHTML=document.getElementById("txtWand").value;

}
}


function setNewCover(albumid,picid)
{

	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.cruisr.de/gallery/ajaxSetCover.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttp.send('aid='+albumid+'&cover='+picid);

		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {

			document.getElementById('myAlbumCover').innerHTML = '<img src="http://www.cruisr.de/Data/Pictures/Photoalbum/400/'+picid+'" style="border: 1px solid #cccccc; padding: 2px; width: 194px; margin: 0px;">';

			}
		};
//		document.getElementById('successNewAlbum').style.display='block';
		//document.getElementById('newAlbum').style.display='none';
//		document.getElementById('txtMessage').blur();

	}
}


function savePicChanges(picid)
{

	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.cruisr.de/gallery/ajaxSavePicChanges.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttp.send('pid='+picid+'&picName='+escape(document.getElementById("picName"+picid).value)+'&myDesc='+escape(document.getElementById("picDesc"+picid).value)+'&myLocation='+escape(document.getElementById("picLocation"+picid).value));


		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {

			alert('Erfolgreich gespeichert!');

			}
		};
//		document.getElementById('successNewAlbum').style.display='block';
		//document.getElementById('newAlbum').style.display='none';
//		document.getElementById('txtMessage').blur();

	}
}


// check for new pm every 30 seks
setTimeout("checkForPM()",5000);
setInterval("checkForPM()",45000);

function checkForPM()
{

 if (xmlHttp) {
     xmlHttp.open('GET', 'http://www.cruisr.de/ajaxGetNewPM.php', true);
     xmlHttp.onreadystatechange = function () {
         if (xmlHttp.readyState == 4) {
			if(xmlHttp.responseText.length > 3 && document.getElementById('optCheckForNewPM').value == 101)
			{

				document.getElementById('divNewPM').style.display='block';
				document.getElementById('newPMvon').innerHTML= xmlHttp.responseText;
			}
			//loadOnlineList();
         }
     };
     xmlHttp.send(null);
 }
}

function updateLastMailCheck()
{
	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.cruisr.de/ajaxUpdateLastMailCheck.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

		xmlHttp.send('uid');

		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {

			document.getElementById('divNewPM').style.display='none';

			}
		};


//		document.getElementById('txtMessage').blur();

	}

}



function changeNotifyStatus()
{

	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.cruisr.de/ajaxChangeNotifyStatus.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

		xmlHttp.send('newStatus='+document.getElementById('NotifyStatus').value);

		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {



			}
		};


//		document.getElementById('txtMessage').blur();

	}

}

function saveOnlineListOpt()
{

	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.cruisr.de/ajaxSaveOnlineListOpt.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

		xmlHttp.send('onlineListVisible='+document.getElementById('onlineListVisible').value+'&onlineListGender='+document.getElementById('onlineListGender').value+'&onlineListKreis='+document.getElementById('onlineListKreis').value);


		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {

			document.getElementById('onlineOpt').style.display='none';
			document.getElementById('onlineListe').style.display='block';
			document.getElementById('showingOnlineListOpt').value='0';
			loadOnlineList();
			}
		};


//		document.getElementById('txtMessage').blur();

	}

}


function saveWIWopt()
{

	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.cruisr.de/kreise/ajaxSaveWIWopt.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

		xmlHttp.send('wiwHeight='+document.getElementById('txtWIWheight').value+'&wiwAnz='+document.getElementById('txtWIWanz').value+'&wiwVisible='+document.getElementById('wiwShowMe').checked);


		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
				document.getElementById('wiwOpt').style.display='none';

			}
		};


//		document.getElementById('txtMessage').blur();

	}

}


// alle 5 Sekunden neue Daten holen
setInterval("loadOnlineList()",20000);

function loadOnlineList() {
	$.get("http://www.cruisr.de/ajaxGetOnlineList.php", { name: "John", time: "2pm" },
   function(data){
	 if($("#showingOnlineListOpt").val()=='0')
	 $('#myOnlineList').html(data);
   });

}

function reloadBoxengasse() {
	$.get("http://www.cruisr.de/you/ajaxReloadBoxengasse.php", { name: "John", time: "2pm" },
   function(data){
	 $('#boxengasseHolder').html(data);
   });
}

function postToBoxengasse() {
	mytext = $('#newBoxengasse textarea').val();
	$.get("http://www.cruisr.de/you/ajaxPostToBoxengasse.php", { text: mytext, time: "2pm" },
   function(data){
	 $('#newBoxengasse textarea').val('').focus();
     $('#picarea').load('http://www.cruisr.de/you/ajaxPicArea.php?id=');
     reloadBoxengasse();
   });
}

function postToMailbox(user) {
	mytext = $('#newBoxengasse textarea').val();
    betrefff = $('#newBoxengasse input').val();
	$.get("http://www.cruisr.de/you/ajaxPostToMailbox.php", { text: mytext, time: "2pm", betreff: betrefff },
   function(data){
	 $('#newBoxengasse textarea').val('').focus();
   });
   $("#mailwrap").load("http://www.cruisr.de/messaging/wrap_user.php?id="+user);
}

function postCommentToBoxengasse(divvar, tavar) {
	mytext = $('#' + divvar + ' textarea').val();
    mytext = tavar + mytext;
	$.get("http://www.cruisr.de/you/ajaxPostCommentToBoxengasse.php", { text: mytext, time: "2pm" },
   function(data){
     reloadBoxengasse();
   });
}

$(document).ready(function(){
	$('textarea').keydown(function(){
		var max = parseInt($(this).attr('maxlength'));

		if(max > 0) {
			if($(this).val().length > max){
				$(this).val($(this).val().substr(0, $(this).attr('maxlength')));
			}

			$(this).parent().find('.charsRemaining').html('' + (max - $(this).val().length) + '');
		}
	});
});

function popUp(aurl) {
    newwindow=window.open(aurl,"mail","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=300");
}
