/* GLOBAL SETTINGS */
var pos=new Array();
var floatInited='no';
var fubarstatus='scroll';
var chatLoaded='wait';
/* EMARVEL */
function show(file,wz,hz){
	helpWindow = window.open(file, '', 'toolbar=no,resizable=no,scrollbars=yes,location=no,width='+wz+',height='+hz+'');
}
function showmsg(file,wz,hz){
	messanger = window.open(file, 'messanger', 'toolbar=no,resizable=no,scrollbars=yes,location=no,width='+wz+',height='+hz+'');
	setTimeout('messanger.focus()',1);
}
function showchat(file,wz,hz){
	chat = window.open(file, 'chat', 'toolbar=no,resizable=yes,scrollbars=yes,location=no,width='+wz+',height='+hz+'');
	setTimeout('chat.focus()',1);
}
function show2(file,wz,hz){
	helpWindow = window.open(file, '', 'toolbar=no,resizable=no,scrollbars=no,location=no,width='+wz+',height='+hz+'');
}
function show3(file,wz,hz){
	helpWindow = window.open(file, '', 'toolbar=yes,status=yes,resizable=no,scrollbars=yes,location=no,width='+wz+',height='+hz+'');
}
function disableForm(theform){
	if(document.all || document.getElementById){
		for(i = 0; i < theform.length; i++){
			var tempobj = theform.elements[i];
			if(tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
				tempobj.disabled = true;
		}
		return true;
	}
	else{
		return false;
	}
}
/* BASE */
function handleFilterPlatinum(filter){
	if(filter=='all')
		cat='all';
	else if(filter=='male')
		cat=0;
	else if(filter=='female')
		cat=1;
	else if(filter=='couple')
		cat=2;
	window.location.href='/browse.php?go=platinum&cat='+cat;
}
/* CHAT */
function launchChat(userid,file,wz,hz){
	eval('var chat'+userid+'=window.open(\''+file+'\',\'\',\'toolbar=no,resizable=no,scrollbars=no,location=no,width='+wz+',height='+hz+'\');');
}
function loadurl(dest,param,type){
	inprogress=true;
	try{
		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e){
		// browser doesn't support ajax. handle however you want
	}
	switch(type){
		case 'status':
			xmlhttp.onreadystatechange=handleStatus;
		break;
		case 'list':
			xmlhttp.onreadystatechange=handleList;
		break;
		case 'infoFloat':
			xmlhttp.onreadystatechange=handleInfoFloat;
		break;
	}	
	xmlhttp.open("POST",dest,true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	xmlhttp.send(param)
}
function handleStatus(){
	if((xmlhttp.readyState==4)&&(xmlhttp.status==200)){
		response=xmlhttp.responseText;
		if(response!=''){
			var pieces=response.split('|');
			response='';

			switch(pieces[2]){
				case 'STANDARD':
					msg=pieces[1]+' wants to chat with you, do you want to chat with them?';
				break;
				case 'NOTIFICATION':
					msg='While you were away, '+pieces[1]+' sent you a instant messenger message. Do you wish to view it now?';
				break;
			}
			
			switch(pieces[3]){
				case '0':
					var confirmpopup=true;
				break;
				case '1':
					var confirmpopup=false;
				break;
			}

			if(confirmpopup)
				var answer=confirm(msg);
			else
				var answer=true;

			if(answer)
				launchChat(pieces[0],'/chatbox.php?type=answer&userid='+pieces[0],474,300);
			else{
				loadurl('/chatbox.php','type=rejectchat&userid='+pieces[0],false);
				var answer=confirm('Permanently block '+pieces[1]+' from chatting with you?');
				if(answer){
					loadurl('/chatbox.php','type=block&userid='+pieces[0]+'&r='+Math.floor(Math.random()*99999),false);
					userList();
				}
			}
		}
	}
}
function handleList(){
	setTimeout('',500);
	if((xmlhttp.readyState==4)&&(xmlhttp.status==200||xmlhttp.status==304)){
		response=xmlhttp.responseText;
		document.getElementById('userlist').innerHTML=response;
		chatLoaded='loaded';
	}
}
function handleInfoFloat(){
	setTimeout('',500);
	if((xmlhttp.readyState==4)&&(xmlhttp.status==200||xmlhttp.status==304)){
		response=xmlhttp.responseText;
		document.getElementById('infoFloat').innerHTML=response;
	}
}
function chatUsers(){
	param=(document.getElementById('chatusers').checked==true?'friends':'all');
	userList(param);
}
function userList(display){
	loadurl('/chatbox.php','display='+display+'&type=userlist&r='+Math.floor(Math.random()*99999),'list');
}
function chatStatus(){
	loadurl('/chatbox.php','type=checkstatus&r='+Math.floor(Math.random()*99999),'status');
}
function blockMember(userid){
	loadurl('/chatbox.php','type=block&userid='+userid+'&r='+Math.floor(Math.random()*99999),false);
	userList();
}
function changeStatus(status){
	loadurl('/chatbox.php','type=changestatus&status='+status+'&r='+Math.floor(Math.random()*99999),false);
}
function addFriend(userid){
	loadurl('/chatbox.php','type=addfriend&userid='+userid+'&r='+Math.floor(Math.random()*99999),false);
	userList();
}
function deleteFriend(userid){
	loadurl('/chatbox.php','type=deletefriend&userid='+userid+'&r='+Math.floor(Math.random()*99999),false);
	userList();
}
/* AGE VERIFY */
function windowSize(){
	if(parseInt(navigator.appVersion)>3){
		if(navigator.appName=="Netscape"||navigator.userAgent.indexOf("opera")==-1){
			winW=window.innerWidth;
			winH=window.innerHeight;
		}
		if(navigator.appName.indexOf("Microsoft")!=-1){
			winW=document.body.offsetWidth;
			winH=document.body.offsetHeight;
		}
	}
	var data=[winW, winH];
	return data;
}
function centerDiv(object,width,height){
	data=windowSize();
	var obj=document.getElementById(object);
	obj.style.left=((data[0]/2)-(width/2))+'px';
	obj.style.top=((data[1]/2)-(height/2)+document.body.scrollTop)+'px';
}
function handleScroll(state){
	var standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body;
	standardbody.style.overflow=state;
}
function confirmAge(){
	var blackout=document.getElementById('blackout');
	var ageverify=document.getElementById('ageverify');
	blackout.style.display='none';
	blackout.style.visibility='hidden';
	ageverify.style.display='none';
	ageverify.style.visibility='hidden';
	var standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body;
	standardbody.style.overflow='';
	createCookie('ageverify',1,365);
}
function initiateAgeVerify(){
	var blackout=document.getElementById('blackout');
	var ageverify=document.getElementById('ageverify');
	blackout.style.display='block';
	blackout.style.visibility='visible';
	blackout.style.opacity=0.8;
	blackout.style.filter = 'alpha(opacity=80)';
	blackout.style.height=document.getElementById('bottom').offsetTop+'px';
	centerDiv('ageverify',400,170);
	ageverify.style.display='block';
	ageverify.style.visibility='visible';
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
/* FUBAR */
function initPos(){
	if(window.Event){
		document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove = getXY;
}
function getXY(e){
	if(!window.Event){
		pos[0]=event.clientX+document.body.scrollLeft;
		pos[1]=event.clientY+document.body.scrollTop;
	} 
	else{
		var de = document.documentElement;
		var b = document.body;
		pos[0]=e.clientX+(de.scrollLeft||b.scrollLeft)-(de.clientLeft||0);
		pos[1]=e.clientY+(de.scrollTop||b.scrollTop)-(de.clientTop||0);
	}
}
function scrollFubar(){
	if(fubarstatus=='scroll'){
		var currentpos=(document.getElementById('fubar').style.left==''?'0px':document.getElementById('fubar').style.left);
		var newpos=currentpos.replace('px','')-2;
		if(newpos==-1424)
			newpos=0;
		document.getElementById('fubar').style.left=newpos+'px';
	}
}
function actionInfoFloat(action,pid,showimg){
	if(chatLoaded=='wait')
		return;
	var infoFloat=document.getElementById('infoFloat');
	switch(action){
		case 'start':
			floatInited='yes';
			posInfoFloat();
			infoFloat.innerHTML='<div style="padding:5px;text-align:center;font-size:11px;color:#CACACA;font-family:Arial">Loading...</div>';
			loadurl('/infoFloat.php','userid='+pid+(showimg!=false?'&showimg=true':''),'infoFloat');
			infoFloat.style.display='block';
		break;
		case 'stop':
			floatInited='no';
			posInfoFloat();
			infoFloat.style.display='none';
		break;
	}
}
function posInfoFloat(){
	if(floatInited=='yes'){
		size=windowSize();
		if((size[0]-pos[0])<345)
			offset=-325;
		else
			offset=0;
		var infoFloat=document.getElementById('infoFloat');
		infoFloat.style.top=pos[1];
		infoFloat.style.left=(pos[0]+15+offset)+'px';
	}
}
function cursor(type){
	this.style.cursor=type;
}
function viewProfile(pid){
	window.location.href='/profile.php?profile='+pid;
}