var menuClosing=false;
var closeTimer;
var gltimeStamp='';
var glverify='';
var warnID='';
var warnObj=null;


var animation = {};
var timers = {};
var hover = {};
var outFunction = {};

function doOutEvent(obj)
{
	var doEvent=true;
	if(typeof(hover[obj])!='undefined')
	{
		if(hover[obj]==true)
		{
			doEvent=false;
		}		
	}
	if(doEvent)
	{
		if(typeof(timers[obj])!='undefined')
		{
			clearTimeout(timers[obj]);
			timers[obj]=undefined;
		}	
		outFunction[obj]();
		hover[obj]=undefined;
		outFunction[obj]=undefined;
	}	
};

function mouseEnter(obj)
{
	outFunction[obj]=function(){};
	hover[obj]=true;
};

function setMouseOutDelay(obj,func,delay)
{
	hover[obj]=false;
	outFunction[obj]=function(){eval(func);};
	if(typeof(timers[obj])!='undefined')
	{
		clearTimeout(timers[obj]);
	}
	timers[obj]=setTimeout("doOutEvent('"+obj+"');",delay);
};


function animateObj(objId,property,start,end,time,units,callback,position)
{
	//time in secods
	//animate every 0.025 seconds - 50 miliseconds
	var numberofjumps=(time*1000)/25;
	var obj=document.getElementById(objId);
	var gap=(end-start)/numberofjumps;
	//obj.style[property]='5px';
	if (!callback){callback=null;} 
	if(position==null && ( typeof(animation[objId+'-'+property+'-'+start]) == 'undefined' ) && (obj.style[property]!=end+units)  )
	{
		//start
		obj.style[property]=start+units;
		animation[objId+'-'+property+'-'+start]=true;
		setTimeout(function(){animateObj(objId,property,start,end,time,units,callback,start);},25);
	}
	else
	{
		//continue
		if( (position<end && gap>=0) || (position>end && gap<0)   )
		{
			obj.style[property]=(position+gap)+units;
			//alert((position+gap)+units);
			setTimeout(function(){animateObj(objId,property,start,end,time,units,callback,position+gap);},25);
		}
		else if ( (position>=end && gap>=0) || (position<=end && gap<0) )
		{
			obj.style[property]=end+units;
			animation[objId+'-'+property+'-'+start]=undefined;
			var tempFunc=function(){eval(callback);};
			tempFunc();
		}
	}
	
};

function leftBarSize() {
	var myHeight = 0;
	if( typeof( window.innerHeight ) == 'number' ) {
		myHeight = window.innerHeight;
	} 
	else if( document.documentElement && document.documentElement.clientHeight ) { myHeight = document.documentElement.clientHeight;
	} else if( document.body && document.body.clientHeight ) {
myHeight = document.body.clientHeight;
	}
if (myHeight>99){
var bar=document.getElementById('leftBar');
bar.style.height=myHeight-99+'px';
}
document.body.style.minHeight=document.documentElement.clientHeight+20+'px';
reSize();
};

function showSearch()
{
	var bsb=document.getElementById('bigSearchBox');
	bsb.style.visibility='visible';
	//bsb.style.height='197px';
	bsb.style.margin='0px 0px 5px 0px';
	animateObj('bigSearchBox','height',0,197,0.15,'px');
	
};

function hideSearch()
{
	var bsb=document.getElementById('bigSearchBox');
	bsb.style.visibility='hidden';
	bsb.style.height='0px';
	bsb.style.margin='0px 0px 0px 0px';
};

function needLogin(msg) {
	alert(msg);
};

function RollIt(ad, n, p) {
	if(n<1 && n > -116) {
	ad.style.bottom=n+'px';
	setTimeout(function(){RollIt(ad, n+(p*5), p);},10);
	}
};
	
function showRollAdd(){
	setTimeout(function(){ RollIt(document.getElementById('rollAd'), -115, 1); },2500);	
	setTimeout(function(){ RollIt(document.getElementById('rollAd'), 0, -1); },30000);	
};

function reportUser(uid, reason) {
if(uid) { loaders.otherContent=new loadContent('calls.php?a=report&id='+uid+'&r='+reason, isitReport, 'GET', null, null); }	
};


function isitReport() {
	if (loaders.otherContent.xmlHttp.readyState==4){ eval(loaders.otherContent.xmlHttp.responseText); }
};



function setCookie(c_name,value,expiredays){ var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays); document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString()); };
function getCookie(cookie_name) { var results=document.cookie.match( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' ); if (results){ return (unescape(results[2]));} else {return null;} } ;

function menuOver(){
if(menuClosing) {clearTimeout(closeTimer); menuClosing=false;}
//show mmenu
document.getElementById("searchBox").style.visibility='visible';
};
function menuOut(){menuClosing=true; closeTimer=setTimeout(function(){document.getElementById("searchBox").style.visibility='hidden';},3000);};
function menuOutNow(){
	if(document.getElementById("searchBox").style.visibility=='visible')
	{
		clearTimeout(closeTimer);
		document.getElementById("searchBox").style.visibility='hidden';
	}
};

function ValidateForm1()  {
	var msn=document.getElementById('msn').value; var forename=document.getElementById('forename').value; var surname=document.getElementById('surname').value; var npassword=document.getElementById('npassword').value; var cnpassword=document.getElementById('cnpassword').value; var gender=document.getElementById('gender').value; var day=document.getElementById('day').value; var month=document.getElementById('month').value; var year=document.getElementById('year').value; var country=document.getElementById('country').value; var area=document.getElementById('area').value; var agree=document.getElementById('agree').checked;
	
	var errors=document.getElementsByTagName('SMALL');
	for(var c=0; c < errors.length; c++) {if(errors[c].className=='errorN') { errors[c].innerHTML=""; errors[c].style.display='none'; } }
	var err2=document.getElementById('jf1').getElementsByTagName('INPUT');
	for(var c=0; c < err2.length; c++) {if(err2[c].className=='box' || err2[c].className=='box invalid') { err2[c].className="box valid"; } }
	
	var fail=false;
	
	if(msn.length < 6) {document.getElementById('msn').className='box invalid'; document.getElementById('ERR_msn').style.display='inline-block'; document.getElementById('ERR_msn').innerHTML="Invalid email address"; fail=true;}
		if( /@(hotmail|live|msn|gmail|googlemail|yahoo|myspace)\./i.test(msn)==false ) {document.getElementById('msn').className='box invalid'; document.getElementById('ERR_msn').style.display='inline-block'; document.getElementById('ERR_msn').innerHTML="(invalid)"; fail=true;  }
	if(forename.length < 2 || forename.length > 200) {document.getElementById('forename').className='box invalid'; document.getElementById('ERR_forename').style.display='inline-block'; document.getElementById('ERR_forename').innerHTML="(too short or too long)"; fail=true;}
	if(surname.length < 2 || surname.length > 200) {document.getElementById('surname').className='box invalid'; document.getElementById('ERR_surname').style.display='inline-block'; document.getElementById('ERR_surname').innerHTML="(too short or too long)"; fail=true;}
	if(npassword.length < 6) {document.getElementById('npassword').className='box invalid'; document.getElementById('ERR_npassword').style.display='inline-block'; document.getElementById('ERR_npassword').innerHTML="(must be at least 6 characters)"; fail=true;}
	if(npassword != cnpassword) {document.getElementById('cnpassword').className='box invalid'; document.getElementById('ERR_cnpassword').style.display='inline-block'; document.getElementById('ERR_cnpassword').innerHTML="(passwords do not match)"; fail=true;}
	if( (day < 1 || day > 31) || (month < 1 || month > 12) || (year < 1900 || year > 3000) || isNaN(year)) {document.getElementById('year').className='box invalid'; document.getElementById('ERR_date').style.display='inline-block'; document.getElementById('ERR_date').innerHTML="(invalid: DD-MM-YYYY)"; fail=true;}
	if(agree != true) {document.getElementById('ERR_agree').style.display='inline-block'; document.getElementById('ERR_agree').innerHTML="You must agree to our terms and conditions"; fail=true;}
	
	
	if(fail) {return false;} else {return true;}
};





function ValidateForm2()  {
	var description=document.getElementById('description').value;
	
	var errors=document.getElementsByTagName('SMALL');
	for(var c=0; c < errors.length; c++) {if(errors[c].className=='errorN') { errors[c].innerHTML=""; errors[c].style.display='none'; } }
	
	var fail=false;

	if(description.length < 8 || description.length > 1000) {document.getElementById('ERR_description').style.display='inline-block'; document.getElementById('ERR_description').innerHTML="(Description must be between 8 and 1000 characters in length)"; fail=true;}
	
	if(fail) {return false;} else {return true;}
};

function ValidateForm3()  {
	var msg=document.getElementById('msg').value;
	var subj=document.getElementById('sub').value;
	
	var errors=document.getElementsByTagName('SMALL');
	for(var c=0; c < errors.length; c++) {if(errors[c].className=='error') { errors[c].innerHTML=""; errors[c].style.display='none'; } }
	
	var fail=false;

	if(msg.length < 10 || msg.length > 5000) {document.getElementById('ERR_msg').style.display='inline-block'; document.getElementById('ERR_msg').innerHTML="Message must be between 10 and 5000 characters"; fail=true;}
	if(subj.length < 1 || subj.length > 50) {document.getElementById('ERR_sub').style.display='inline-block'; document.getElementById('ERR_sub').innerHTML="Message Subject must be between 1 and 50 characters"; fail=true;}
	
	if(fail) {return false;} else {return true;}
};

function settingsIF(reloadp)
{
	document.getElementById('iframeContent').src='iframe.php?a=settings&r='+reloadp;
	document.getElementById('pageHide').style.visibility='visible';
	
};

function iframePage(url)
{
	document.getElementById('iframeContent').src=url;
	document.getElementById('pageHide').style.visibility='visible';
};

function reportProfile(id)
{
	document.getElementById('iframeContent').src='iframe.php?a=report&t=sub&id='+id;
	document.getElementById('pageHide').style.visibility='visible';
	
};

function connectProfile(service)
{
	document.getElementById('iframeContent').src='iframe.php?a=connect&site='+service;
	document.getElementById('pageHide').style.visibility='visible';
	
};

function openOauth(url)
{
	newWindow=window.open(url,'oauthwindow','width=500,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
		newWindow.focus();
};

function leftBarScroll() {
var bar=document.getElementById('leftBar');
var scrollAmount=document.documentElement.scrollHeight-document.documentElement.clientHeight;
var scrollNo=document.documentElement.scrollTop+document.body.scrollTop;
bar.scrollTop=((bar.scrollHeight-bar.offsetHeight)/100)*(scrollNo/(scrollAmount/100));
};

function settingsFilter() {
	for (var i=0; i < document.settings.filter.length; i++)
   {
   if (document.settings.filter[i].checked)
      {
      var rad_val = document.settings.filter[i].value;
      }
   }

setCookie("filter", rad_val, "365");
};

function elink(eurl,neww) {
	
	if(neww)
	{
		window.open(eurl,'NeedAddys','width=450,height=400,toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
	}
	else
	{
		window.location.href=eurl;
	}
};

function animateIt(ob, height, dir, end, func) {
if((dir>0 && height<end) || (dir<0 && height>end)) {ob.style.height=height+(dir*26)+'px'; setTimeout(function(){animateIt(ob, height+(dir*26), dir, end, func)}, 20); } else {ob.style.height=end+'px'; if(func){ob.style.height=func;} }
}

function warnOpen(id,obj)
{
	warnID=id;
	warnObj=obj;
	document.getElementById('iframeContent').src='iframe.php?a=warn';
	var lgb=document.getElementById('iframeBox');
	document.getElementById('pageHide').style.visibility='visible';
	
};

function showWarn()
{
	viewAddy(warnID,warnObj);
	document.getElementById('xxI-'+warnID).style.display='none';
};


function largePhoto(id,num)
{
	
	document.getElementById('iframeContent').src='iframe.php?a=uimg&id='+id+'&n='+num;
	var lgb=document.getElementById('iframeBox');
	//lgb.style.visibility='visible';
	lgb.style.height=(document.getElementById('pageHide').offsetHeight-96)+'px';
	lgb.style.width=(document.getElementById('pageHide').offsetWidth-96)+'px';
	lgb.style.left='-'+(document.getElementById('pageHide').offsetWidth-80)/2+'px';
	var top=(document.getElementById('pageHide').offsetHeight/2)-(lgb.offsetHeight/2);
	lgb.style.top='40px';
	document.getElementById('pageHide').style.visibility='visible';
	
};

function sizeIframe(pad)
{
	if(!pad){pad=40;}
	var lgb=document.getElementById('iframeBox');
	//lgb.style.visibility='visible';
	lgb.style.height=(document.getElementById('pageHide').offsetHeight-(pad*2 +16))+'px';
	var wwid=document.getElementById('pageHide').offsetWidth;
	if(wwid>920){wwid=920;}
	lgb.style.width=(wwid-(pad*2 +16))+'px';
	lgb.style.left='-'+(wwid-(pad*2))/2+'px';
	var top=(document.getElementById('pageHide').offsetHeight/2)-(lgb.offsetHeight/2);
	lgb.style.top=pad+'px';
	
};

function newMessage(id)
{
	
	document.getElementById('iframeContent').src='iframe.php?a=newmail&id='+id;
	var lgb=document.getElementById('iframeBox');
	//lgb.style.visibility='visible';
	document.getElementById('pageHide').style.visibility='visible';
	
};

function pleaseLogin()
{
	
	document.getElementById('iframeContent').src='iframe.php?a=login';
	var lgb=document.getElementById('iframeBox');
	//lgb.style.visibility='visible';
	document.getElementById('pageHide').style.visibility='visible';
	
};

function addAddy(id,type)
{
	
	document.getElementById('iframeContent').src='adduser.php?id='+id+'&s='+type+'&t='+gltimeStamp+'&v='+glverify;
	var lgb=document.getElementById('iframeBox');
	lgb.style.visibility='visible';
	lgb.style.height='180px';
	lgb.style.width='400px';
	lgb.style.left='-200px';
	var top=(document.getElementById('pageHide').offsetHeight/2)-(lgb.offsetHeight/2);
	lgb.style.top=top+'px';
	document.getElementById('pageHide').style.visibility='visible';
	
};


function closeAddy(ref)
{
	document.getElementById('iframeContent').src='iframe.php?a=blank';
	var lgb=document.getElementById('iframeBox');
	lgb.style.height='10px';
	lgb.style.width='10px';
	lgb.style.visibility='hidden';
	//document.getElementById('pageHide').style.visibility='hidden';
	if(ref)
	{
		window.location.href=window.location.href;
	}
	else
	{
		document.getElementById('pageHide').style.visibility='hidden';
	}
};

function viewAddy(id,obj)
{
	loaders.otherContent=new loadContent('calls.php?a=addView&id='+id, evalRespo, 'GET', null, null);
	var listing=obj.parentNode.parentNode;
	animateIt(listing,78,1,200,'auto');
	obj.innerHTML='Close Profile';
	obj.onclick=function(){hideAddy(id,obj);};
	
};

function evalRespo()
{
	
};

function hideAddy(id,obj)
{
	var listing=obj.parentNode.parentNode;
	listing.style.height='78px';
	obj.innerHTML='View Profile';
	obj.onclick=function(){viewAddy(id,obj);};
};




function likeUser(uid) {
if(uid) { loaders.otherContent=new loadContent('calls.php?a=like&id='+uid, isitLike, 'GET', null, null); }
};

function isitLike() {
	if (loaders.otherContent.xmlHttp.readyState==4){ eval(loaders.otherContent.xmlHttp.responseText); }
};

function windowWidth() {
	if(typeof(window.innerWidth)=='number'){return window.innerWidth;} 
	else if(document.documentElement.clientWidth){return document.documentElement.clientWidth;}	
	else if(document.body.clientWidth){return document.body.clientWidth;} 
};

function reSize(){
var width=windowWidth();
var contents=document.getElementById('rightBar');
var ads=document.getElementById('leftBar');
var shadow=document.getElementById('rightShadow');

if(width<870) {contents.style.marginRight='5px'; ads.style.visibility='hidden'; shadow.style.visibility='hidden';}
else {contents.style.marginRight='125px'; ads.style.visibility='visible';  shadow.style.visibility='visible';}	
	
};

function savePhoto(num) {
	if(num>0) {
		loaders.otherContent=new loadContent('calls.php?a=changeImage&s='+num, updatePhoto, "GET", num, null);	
	}	
	else if(num==0){
		loaders.otherContent=new loadContent('calls.php?a=changeImage&s='+num+'&url='+document.getElementById('picurl').value, updatePhoto, "GET", num, null);	
	}
};
function updatePhoto() {
	if (loaders.otherContent.xmlHttp.readyState==4){ 
		if(loaders.otherContent.xmlHttp.responseText=='error') { if(loaders.otherContent.context==0) { alert('Error: The image URL you entered could not be found!');} else {alert('Error: Your image could not be changed!');} }
		else {document.getElementById('editPic').src=loaders.otherContent.xmlHttp.responseText; } 
		document.getElementById('changePic').style.display='none';
	}
};

function saveOps(){
	if(document.getElementById('sp1').checked==true){setCookie('sp1',1,'0');}
	else {setCookie('sp1',0,'0'); }
	if(document.getElementById('sp2').checked==true){setCookie('sp2',1,'0');}
	else {setCookie('sp2',0,'0');}
	if(document.getElementById('sp3').checked==true){setCookie('sp3',1,'0');}
	else {setCookie('sp3',0,'0');}
	if(document.getElementById('cam').checked==true){setCookie('cam',1,'0');}
	else {setCookie('cam',0,'0');}
	if(document.getElementById('pic').checked==true){setCookie('pic',1,'0');}
	else {setCookie('pic',0,'0');}
	if(document.getElementById('male').checked==true){setCookie('male',1,'0');}
	else {setCookie('male',0,'0');}
	if(document.getElementById('female').checked==true){setCookie('female',1,'0');}
	else {setCookie('female',0,'0');}
	if(document.getElementById('male').checked==false && document.getElementById('female').checked==false) {setCookie('male',1,'0'); setOps();}
	if(document.getElementById('sp1').checked==false && document.getElementById('sp2').checked==false && document.getElementById('sp3').checked==false) {setCookie('sp1',1,'0'); setOps();}
	
	var agelow=document.getElementById('agelow');
	var agelowOps=agelow.getElementsByTagName('option');
	for ( var i=0; i < agelowOps.length; i++ ) {
		if(agelowOps[i].selected==true) {
			setCookie('agelow',agelowOps[i].value,'0');
		}
	}
	
	var agehigh=document.getElementById('agehigh');
	var agehighOps=agehigh.getElementsByTagName('option');
	for ( var i=0; i < agehigh.length; i++ ) {
		if(agehighOps[i].selected==true) {
			setCookie('agehigh',agehighOps[i].value,'0');
		}
	}
	
	var country=document.getElementById('country');
	var countryOps=country.getElementsByTagName('option');
	for ( var i=0; i < country.length; i++ ) {
		if(countryOps[i].selected==true) {
			setCookie('country',countryOps[i].value,'0');
		}
	}
	
	};
	
function setOps(){
	if(!getCookie('sp1')) { //set cookies
		setCookie('sp1',1,'0');
		setCookie('sp2',1,'0');
		setCookie('sp3',1,'0');
		setCookie('cam',0,'0');
		setCookie('pic',0,'0');
		setCookie('male',1,'0');
		setCookie('female',1,'0');
		setCookie('agelow',15,'0');
		setCookie('agehigh',60,'0');
		setCookie('country','All','0');
	}
	
	if(getCookie('sp1')==1){document.getElementById('sp1').checked=true; }
	else {document.getElementById('sp1').checked=false; }
	if(getCookie('sp2')==1){document.getElementById('sp2').checked=true;}
	else {document.getElementById('sp2').checked=false;}
	if(getCookie('sp3')==1){document.getElementById('sp3').checked=true;}
	else {document.getElementById('sp3').checked=false;}
	if(getCookie('cam')==1){document.getElementById('cam').checked=true;}
	else {document.getElementById('cam').checked=false;}
	if(getCookie('pic')==1){document.getElementById('pic').checked=true;}
	else {document.getElementById('pic').checked=false;}
	if(getCookie('male')==1){document.getElementById('male').checked=true;}
	else {document.getElementById('male').checked=false;}
	if(getCookie('female')==1){document.getElementById('female').checked=true;}
	else {document.getElementById('female').checked=false;}
	
	var agelow=document.getElementById('agelow');
	var agelowOps=agelow.getElementsByTagName('option');
	for ( var i=0; i < agelowOps.length; i++ ) {
		if(agelowOps[i].value==getCookie('agelow')) {
			agelowOps[i].selected=true;
		}
	}
	var agehigh=document.getElementById('agehigh');
	var agehighOps=agehigh.getElementsByTagName('option');
	for ( var i=0; i < agehighOps.length; i++ ) {
		if(agehighOps[i].value==getCookie('agehigh')) {
			agehighOps[i].selected=true;
		}
	}
	var country=document.getElementById('country');
	var countryOps=country.getElementsByTagName('option');
	for ( var i=0; i < countryOps.length; i++ ) {
		if(countryOps[i].value==getCookie('country')) {
			countryOps[i].selected=true;
		}
	}
};

function saveResOps() {
	var country=document.getElementById('pages');
	var countryOps=country.getElementsByTagName('option');
	for ( var i=0; i < country.length; i++ ) {
		if(countryOps[i].selected==true) {
			setCookie('ppp',countryOps[i].value,'0');
		}
	}
};



var loaders = { 
	mainContent:{xmlHttp:'e' }, otherContent:{xmlHttp:'e'}
};

function userLogin() { 
var d = new Date();
var user=document.getElementById('username').value;	var pass=document.getElementById('password').value; var params='username='+user+'&password='+pass+'&REM='+document.getElementById('REM').value+'&t='+gltimeStamp+'&v='+glverify; var type='POST';
loaders.otherContent=new loadContent('clogin.php', loginResponse, type, user, params);
};

function loginResponse() {
if (loaders.otherContent.xmlHttp.readyState==4){ 
if (loaders.otherContent.xmlHttp.responseText=='true') { /*login*/window.location="home.php"; }
else {/*login failed*/ document.getElementById('errorBox').innerHTML=loaders.otherContent.xmlHttp.responseText; document.getElementById('username').value=''; document.getElementById('password').value=''; }
}
};

function loadContent(url, callback, type, context, params) { 
this.url=url; this.context=undefined;
try {this.xmlHttp=new XMLHttpRequest();} 
catch(e){ 
try{this.xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");} 
catch(e){ this.xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}	
}
this.context=context; 
this.xmlHttp.open(type,this.url,true);
if(params) {this.xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); this.xmlHttp.setRequestHeader("Content-length", params.length); }
this.xmlHttp.send(params);
this.xmlHttp.onreadystatechange=callback;
}; 

//window.onscroll=function(){leftBarScroll();};
window.onload=function(){setOps();};
