var slideShowSpeed = 6000;
var crossFadeDuration = 5;
var Users = new Array();
var Names = new Array();
var preLoad = new Array();
var t = 0;
var p = 0;
var j = 1;
var profileboxes=0;
var prefheight=90;
var selectedGift="";
var selectedCat="";
var divheight=105;

function clearit(val) {
	var lookval = ""+document.getElementById(val).value;
	lookval = lookval.toLowerCase();
	if (lookval==val+"...") {
		document.getElementById(val).value="";
	}
}

function swap(id,rownum) {
	try {
		document.getElementById(id).filters[0].Apply();
	}
	catch(e) {}

	height=""+document.getElementById(id).style.height;
	if (height==divheight+"px") { document.getElementById("img"+id).src="/images/plus"+rownum+".gif" } else { document.getElementById("img"+id).src="/images/minus"+rownum+".gif" }
	if (height==divheight+"px") { height="20px" ; } else { height=divheight+"px"; }
	document.getElementById(id).style.height=height;
	try { document.getElementById(id).filters[0].Play(); } catch(e) {}
}

function openClose(id,rownum,openclose) {
	try { document.getElementById(id).filters[0].Apply(); } catch(e) {}
	height=""+document.getElementById(id).style.height;
	if (openclose=="close") { document.getElementById("img"+id).src="/images/plus"+rownum+".gif" } else { document.getElementById("img"+id).src="/images/minus"+rownum+".gif" }
	if (openclose=="close") { height="20px" ; } else { height=prefheight+"px"; }
	document.getElementById(id).style.height=height;
	try { document.getElementById(id).filters[0].Play(); } catch(e) {}
}

function getSel(id) {
	var txt = '';
	if (window.getSelection) {
		txt = window.getSelection();
	}
	else if (document.getSelection) {
		txt = document.getSelection();
	}
	else if (document.selection) {
		txt = document.selection.createRange().text;
	}
	else return;
	if (txt!="") {
		var words=""+document.getElementById(id).innerHTML;
		try { txt=txt.replace(/&/,"&amp;") } catch(e) {}
		words=words.replace(txt,"<i class='highlighted'>"+txt+"</i>")		
		document.getElementById(id).innerHTML=words
		selectedGift=txt;
		selectedCat=""+id;
		selectedCat=selectedCat.replace("prefcat","");
		try { document.execCommand("Unselect"); } catch(e) {}
		document.getElementById("search"+selectedCat).style.display="block";
		document.getElementById("surprise"+selectedCat).style.display="block";
		document.getElementById("search"+selectedCat).onclick=doSearch;
		document.getElementById("surprise"+selectedCat).onclick=doSurprise;

	}

}

function runSlideShow(){
	loadPictures();
	if (document.all){
		document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"
		document.images.SlideShow.filters.blendTrans.Apply()
	}
	document.images.SlideShow.src = preLoad[j].src
	document.getElementById("memberinfo").innerHTML = '<a href="/profile/view.asp?user='+Users[j]+'">'+Names[j]+' <b>View...</b></a>'
	if (document.all){
		document.images.SlideShow.filters.blendTrans.Play()
	}
	j = j + 1
	if (j == p) j=1
	t = setTimeout('runSlideShow()', slideShowSpeed)
}


function loadPictures() {
    return false;

	p = Users.length

	for (i = 1; i < p; i++){
		preLoad[i] = new Image()
		preLoad[i].src = '/viewimage.asp?type=user&id='+Users[i]+'.jpg&height=135'
	}
}

function openAllProfile() {

	if (document.getElementById("openall").innerHTML=="Open All") { 
		for (var num=1;num<=profileboxes;num++) {	
			try { openClose(num,1,"open"); } catch(e) {}		 
		}
		document.getElementById("openall").innerHTML="Close All" ;
	} else  { 
		for (var num=1;num<=profileboxes;num++) {	
			try { openClose(num,1,"close"); } catch(e) {}		 
		}
		document.getElementById("openall").innerHTML="Open All" ;
	} 
}

function openAllPreferences() {

	if (document.getElementById("openall").innerHTML=="Open All") { 
		for (var num=1;num<=prefboxes;num++) {	
			try { openClose(num,1,"open"); } catch(e) {}
		}
		document.getElementById("openall").innerHTML="Close All" ;
	} else  { 
		for (var num=1;num<=prefboxes;num++) {	
			try { openClose(num,1,"close"); } catch(e) {}		 
		}
		document.getElementById("openall").innerHTML="Open All" ;
	} 
}

function doSelectedText(selUser,selText,action,idnum) {
	if (idnum>0) { selectedCat=idnum ; }
	if (selectedGift=="" && !(idnum>0)) { 
		alert(selText)
	} else { 
		try { selectedGift=selectedGift.replace(/&/,"%26"); } catch(e) {}
		try { selectedGift=selectedGift.replace(/\+/,"%2B"); } catch(e) {}
		
		if (action=="searchgoogle") {
			document.location.href="http://www.google.co.uk/search?q="+selectedGift
		} else {			
			document.location.href="toolbox.asp?action="+action+"&user="+selUser+"&gift="+selectedGift+"&cat="+selectedCat
		}
	}
}

	
function submitPrintHint() {
	try {
		var incsosword=""+document.getElementById('includesosword').checked;
		if (incsosword=="true") { incsosword="1" } else { incsosword="" }
		msg=""+document.getElementById('message').value;
		msg = msg.replace(/\n/g,"<br>");
		document.location.href="printhint.asp?msg="+msg+"&sos="+incsosword
	
	} catch(e) {}

}

function submitEmailHint() {
	try {
		document.getElementById("emailhint").style.display="block"		
	
	} catch(e) {}

}

function sendEmailHint() {
	try {
		var incsosword=""+document.getElementById('includesosword').checked;
		if (incsosword=="true") { incsosword="1" } else { incsosword="" }
		msg=""+document.getElementById('message').value;
		msg = msg.replace(/\n/g,"<br>");
		emailadd=""+document.getElementById('emailadd').value;
		document.location.href="emailhint.asp?email="+emailadd+"&msg="+msg+"&sos="+incsosword
	
	} catch(e) {}

}

function bookmarkNow(){
    var title=document.title
    var url=document.location.href

    if (window.sidebar) window.sidebar.addPanel(title, url,"");

    else if( window.opera && window.print )
    {
    var mbm = document.createElement('a');
    mbm.setAttribute('rel','sidebar');
    mbm.setAttribute('href',url);
    mbm.setAttribute('title',title);
    mbm.click();
    }

    else if( document.all ) window.external.AddFavorite( url, title);

}

function doBigPicture(id) {

	picURL='/viewimage.asp?type=user&id='+id+'.jpg&width=600&refresh=1';
	picWidth=600;
	picHeight=document.getElementById("preloadfullpic").height;

	newWindow=window.open(picURL,'newWin','toolbar=no,width='+picWidth+',height='+picHeight)
	newWindow.document.write('<html><head><title>Photo</title><\/head><body onclick="window.close()" background="'+picURL+'"><\/body><\/html>')
	newWindow.resizeBy(picWidth-newWindow.document.body.clientWidth,picHeight-newWindow.document.body.clientHeight)
	newWindow.focus()

}

function savePref(id) {
	text=""+document.getElementById("text"+id).value;
	text=text.replace(/\r/g,"");
	text=text.replace(/\n\n/g,"\n");
	text=text.replace(/\n/g,", ");
	text=text.replace(/\"/g,"“");
	text=text.replace(/\. ,/g,". ");
	text=text.replace(/\.,/g,". ");
	text=text.replace(/,  /g,", ");
	text=text.replace(/, , /g,", ");
	text=text.replace(/, ,/g,",");
	text=text.replace(/,,/g,",");
	text=text.replace(/ ,/g,",");
	var privatePref=0;
	if (document.getElementById("priv"+id).checked) { privatePref=1; }
	var surp=document.getElementById("surp"+id).value;
	var club=document.getElementById("club"+id).value;
	var formHTML='<form name="submitform'+id+'" id="submitform'+id+'" target="ajax" action="savetext.asp" method="post">';
	formHTML+='<input type="hidden" name="id" value="'+id+'" />';
	formHTML+='<input type="hidden" name="private" value="'+privatePref+'" />';
	formHTML+='<input type="hidden" name="text" value="'+text+'" />';
	formHTML+='<input type="hidden" name="surp" value="'+surp+'" />';
	formHTML+='<input type="hidden" name="club" value="'+club+'" />';
	formHTML+='</form>';
	document.getElementById("dynamicform").innerHTML=formHTML;
	document.forms["submitform"+id].submit();
}

/* Facebook connect */
function checkFBStatus(action) {
	$.getScript("/check_fb_status.php?" + action);
}

function updateUserBox() {
	var user_box = $("#members")[0];

    if (user_box) {
		user_box.innerHTML =
			'<div class="fb_user_box">'
			+ '<h3 class="signin">Logged In</h3>'
			+ "<span><fb:profile-pic uid='loggedinuser' facebook-logo='false' style='float:left'></fb:profile-pic>"
			+ "<p>Welcome, <b><fb:name uid='loggedinuser' useyou='false' linked='false'></fb:name></b>.</p><p>You are signed in with your Facebook account.</p>"
			+ "</span></div>";

		// because this is XFBML, we need to tell Facebook to re-process the document
		FB.XFBML.Host.parseDomTree();
	}
}

function updateMenu() {
	$.get("/inc/topmenu.js.asp", function(data){
		clean = data.replace(/document\.write \('/g, '');
		clean = clean.replace(/'\)/g, '');
		$('#topmenu').html(clean);
	});
}