var havenewmsgid = 0;
var isie = !navigator ? 0 : navigator.userAgent.indexOf("MSIE") >= 0;
var iswindows = !navigator ? 0 : navigator.platform.indexOf("Win") >= 0;
var revalidation,membertype,imageserver,thumbnailwidth,thumbnailheight,thumbnailnamelimit,memberid,pagewidth,
	imwindowwidth,imwindowheight,fronlinewidth,fronlineheight,panewidth,paneheight,
	messagetab,onmsgtab,refreshinbox,iphone,iphoneapp,canhover,menuopacity,menuanimation,
	dialogopacity,dialoganimation,buttongraphicstyle,thumbnailcornerradius;
var sectionname,altkey,dev1 = 0,admin = 0;
function pageinit(reval,mtype,ims,tw,th,tnl,mid,pw,imww,imwh,fronlw,fronlh,pnw,pnh,mt,onm,ref,ip,ipa,ch,mop,ma,dop,dan,bgs,tcr,ugl) {
	revalidation = reval;
	membertype = mtype;
	imageserver = ims;
	thumbnailwidth = tw;
	thumbnailheight = th;
	thumbnailnamelimit = tnl;
	memberid = mid;
	pagewidth = pw;
	imwindowwidth = imww;
	imwindowheight = imwh;
	fronlinewidth = fronlw;
	fronlineheight = fronlh;
	panewidth = ip ? 320 : pnw;
	paneheight = pnh;
	messagetab = mt;
	onmsgtab = onm;
	refreshinbox = ref;
	iphone = ip
	iphoneapp = ipa;
	canhover = ch;
	menuopacity = mop/100;
	menuanimation = ma;
	dialogopacity = dop/100;
	dialoganimation = dan;
	buttongraphicstyle = bgs;
	thumbnailcornerradius = tcr;
	if (iphone) {
		if (iphoneapp) document.write('<meta name=viewport content="width=device-width; initial-scale=1.0; minimum-scale=1.0; user-scalable=0">');
		else {
			if (!window.orientation) document.write('<meta name=viewport content="width=device-width, initial-scale=1.0, maximum-scale=1.5, minimum-scale=1.0, user-scalable=0">');
			else document.write('<meta name=viewport content="width=device-height, initial-scale=1.5, maximum-scale=1.5, minimum-scale=1.0, user-scalable=0">');
			document.write('<link rel="apple-touch-icon" href="'+imageserver+'/membertype'+membertype+'/apple-touch-icon.png">');
		}
	}
	if ((ugl && (ugl != -2  || memberid)) && navigator && navigator.userAgent.indexOf("iPhone") > 0) window.addEventListener('load',function () {setTimeout(function(){locationtrack(null)},1000)});
}
function myonunload() {
	undimbutton();
}
function logon() {
	if (location.href.indexOf("viewprofile.cfm") > 0) location = "logon.cfm?target="+encodeURIComponent(location.href);
	else location = "logon.cfm";
}
function selectfield(f) {
	if (!document.activeElement.name) {
		f.focus();
		f.select();
	}
}
function htmlembed(thetag) {
	document.write(thetag);
}
var datetrack1 = null,datetrack2 = null, datelocked = 0;
var timetrack1 = null,timetrack2 = null, timelocked = 0;
function updatedate(n,isbirthdate) {
	var f = document.theform;
	var dow = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
	var m = f[n+"_m"].value*1;
	var d = f[n+"_d"].value*1;
	var y = f[n+"_y"].value*1;
	if (m < 0 || d < 0 || y < 0) {
		f[n].value = "???";
		return;
	}
	var result = '-';
	var maxd = [31,28,31,30,31,30,31,31,30,31,30,31][m-1]+(m == 2 && !(y%4));
	if (d > maxd) {
		f[n+"_d"].selectedIndex = maxd-1;
		d = maxd;
	}
	var thedate = new Date(y,m-1,d,0,0,0,0);
	for (var i = 28; i <= 30; i++) {
		f[n+"_d"].options[i].disabled = i >= maxd;
	}
	if (thedate.getMonth() == m-1) result = dow[thedate.getDay()];
	if (iphone) result = result.substr(0,3);
	if (!isbirthdate) document.getElementById(n+"_dow").innerHTML = result;
	f[n].value = m+"/"+d+"/"+y;
	if (n == datetrack1) {
		var d1 = f[n+"_y"].selectedIndex*10000+f[n+"_m"].selectedIndex*100+f[n+"_d"].selectedIndex;
		var d2 = f[datetrack2+"_y"].selectedIndex*10000+f[datetrack2+"_m"].selectedIndex*100+f[datetrack2+"_d"].selectedIndex;
		if (datelocked < 0) datelocked = d1 == d2;
		if (datelocked || d1 > d2) {
			f[datetrack2+"_m"].selectedIndex = f[n+"_m"].selectedIndex;
			f[datetrack2+"_d"].selectedIndex = f[n+"_d"].selectedIndex;
			f[datetrack2+"_y"].selectedIndex = f[n+"_y"].selectedIndex;
			updatedate(datetrack2);
			datelocked = 1;
			if (timetrack1) {
				timelocked = 1;
				updatetime(timetrack1);
			}
		}
	} else if (n == datetrack2) datelocked = 0;
}
function setdatelock(n1,n2) {
	datelocked = -1;
	datetrack1 = n1;
	datetrack2 = n2;
}
function updatetime(n) {
	var f = document.theform;
	var h = f[n+"_h"].value*1;
	var m = f[n+"_m"].value;
	f[n].value = h%12+12*!(h%12)+":"+m+(h < 12 ? " am" : " pm");
	m *= 1;
	if (n == timetrack1) {
		var t1 = h*100+m;
		var t2 = f[timetrack2+"_h"].value*100+f[timetrack2+"_m"].value*1;
		var sameday = 1;
		sameday = f[datetrack1+"_y"].selectedIndex*10000+f[datetrack1+"_m"].selectedIndex*100+f[datetrack1+"_d"].selectedIndex == f[datetrack2+"_y"].selectedIndex*10000+f[datetrack2+"_m"].selectedIndex*100+f[datetrack2+"_d"].selectedIndex;
		if (!sameday) timelocked = 0;
		else if (timelocked < 0) timelocked = t1 == t2;
		if (timelocked || sameday && t1 > t2) {
			f[timetrack2+"_h"].selectedIndex = f[n+"_h"].selectedIndex;
			f[timetrack2+"_m"].selectedIndex = f[n+"_m"].selectedIndex;
			timelocked = 1;
		}
	} else if (n == timetrack2) timelocked = 0;
}
function settimelock(n1,n2) {
	timelocked = -1;
	timetrack1 = n1;
	timetrack2 = n2;
}
function showswf(r,swf) {
	//document.getElementById("hiddenswf"+r).style.backgroundColor = "transparent";
	document.getElementById("hiddenswf"+r).innerHTML = decodeURIComponent(swf);
}
function hiddenswf(w,h,swf) {
	var r = Math.random();
	var imagew = Math.min(Math.min(32,w),h);
	var clicktext = h > 50 && w > 100 ? "<br>Click to Play" : "";
	document.write("<div style='background-color:gray; width:"+w+"px; height:"+h+"px;' id=hiddenswf"+r+"><table width=100% height=100% class=datat2><tr><td style='text-align:center;vertical-align:middle'><a href=\"javascript:showswf("+r+",'"+encodeURIComponent(swf)+"')\"><img src="+imageserver+"/pieces/playbutton.jpg width="+imagew+"></a>"+clicktext+"</table></div>");
}
function captureevents(theobj,movef,releasef,cancelf) {
	if (document.attachEvent) {
		theobj.attachEvent("onmousemove",movef);
		theobj.attachEvent("onmouseup",releasef);
	} else if (window.Touch) {
		theobj.addEventListener("touchmove",movef,true);
		theobj.addEventListener("touchend",releasef,true);
		theobj.addEventListener("touchcancel",cancelf ? cancelf : releasef,true);
	} else {
		theobj.addEventListener("mousemove",movef,true);
		theobj.addEventListener("mouseup",releasef,true);
	}
}
function releaseevents(theobj,movef,releasef,cancelf) {
	if (document.attachEvent) {
		theobj.detachEvent("onmousemove",movef);
		theobj.detachEvent("onmouseup",releasef);
	} else if (window.Touch) {
		theobj.removeEventListener("touchmove",movef,true);
		theobj.removeEventListener("touchend",releasef,true);
		theobj.removeEventListener("touchcancel",cancelf ? cancelf : releasef,true);
	} else {
		theobj.removeEventListener("mousemove",movef,true);
		theobj.removeEventListener("mouseup",releasef,true);
	}
}
function cancelbubble(e) {
	if (document.attachEvent) {
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
	else e.preventDefault();
}
function prevdragstart(e) {
	captureevents(document,cancelbubble,prevdragend);
	cancelbubble(e);
}
function prevdragend(e) {
	releaseevents(document,cancelbubble,prevdragend);
	return (false);
} 

function securephotos(idlist) {	// id list. Can use * suffix if using drag code protocol.
	idlist = idlist.split(",");
	for (var j = 0; j < idlist.length; j++) {
		var id = idlist[j];
		if (id.substr(id.length-1) != "*") {
			var myobj = document.getElementById(id);
			myobj.oncontextmenu = function () {return false};
			myobj.onmousedown = function (e) {prevdragstart(e)}; 
		}
		else {
			var prefix = id.substr(0,id.length-1);
			for (var i = 0; i < numobjs; i++) {
				var myobj = document.getElementById(prefix+theobj[i].dbid);
				myobj.oncontextmenu = function () {return false};
				myobj.onmousedown = function (e) {prevdragstart(e)}; 
			}
		}
	}
}
// Side menu functions
function dosm(t,u) {
	if (u.indexOf("javascript:")) t.onclick = function (e) {location = u};
	else t.onclick = function (e) {eval(u.substr(11,1000))};
	if (t.className.indexOf(" hover") < 0) t.className += " hover";
	t.onmouseover = function (e) {if (t.className.indexOf(" hover") < 0) t.className += " hover"};
	t.onmouseout = function (e) {t.className = t.className.replace(/ hover/g,"")};
}
// Tab functions
var tabdata = [];
var tabsuffix = "";
function tabloc(tu) {
	var e;
	var oldcursor = document.body.style.cursor;
	if (tu == "") return;
	try {
		document.body.style.cursor = "wait";
		location = tu;
	} catch (e) {
		document.body.style.cursor = oldcursor;
		alert("Unable to load page.");
	}
}
function tabro(tabobj,over) {
	if (tabobj.className != "tabon"+tabsuffix) {
		tabobj.className = (over ? "tabro" : "taboff")+tabsuffix;
	}
	return (true);
}
function tabcl(tabobj,e,g) {
	if (tabobj.className.indexOf("tabdis"+tabsuffix) < 0) {
		var tabinfo = tabobj.id.split(".");
		var tabseq = tabinfo[1];
		var tabon = tabobj.className == "tabon"+tabsuffix;
		if (tabdata[tabseq][0] || !tabon) {
			for (var i = 1; i < tabdata[tabseq].length; i++) {
				var tabobj2 = document.getElementById("tb."+tabseq+"."+i);
				if (tabobj2.className != "tabdis"+tabsuffix) {
					tabobj2.className = (tabobj === tabobj2 ? "tabon" : "taboff")+tabsuffix;
				}
			}
			if (tabdata[tabseq][0] || !tabon) tabdata[tabseq][tabinfo[2]]();
		}
	}
	if (e) prevdragstart(e);
	return (true);
}
function selecttab(tabseq,tabnum,doit) {
	if (doit) tabcl(document.getElementById("tb."+tabseq+"."+tabnum),null);
}
function inittabs(tabseq,tabf) {
	var cn = document.getElementById("tb."+tabseq+".1").className;
	tabsuffix = cn.split(" ").slice(1).join(" ");
	if (tabsuffix != "") tabsuffix = " "+tabsuffix;
	if (cn.indexOf("inner") >= 0) tabsuffix = "inner"+tabsuffix;
	tabdata[tabseq] = tabf;
	for (var i = 1; i < tabf.length; i++) {
		var tabobj = document.getElementById("tb."+tabseq+"."+i);
		if (tabobj.className.indexOf("tabdis") < 0) {
			tabobj.onmouseover = function () {tabro(this,1)};
			tabobj.onmouseout = function () {tabro(this,0)};
		}
		tabobj.onmousedown = function (e) {return tabcl(this,e,1)};
	}			
}
// Button functions
var buttonobj = "";
var oldbuttontext = "";
function formchanged(myform) {
	if (!myform) myform = document.theform;
	var theelement = "";
	for (var i = 0; i < myform.elements.length; i++) {
		theelement = myform.elements[i];
		if (theelement.name != "") {
			switch (theelement.type) {
			case "reset":
			case "submit":
			case "button":
			case "hidden":
				break;
			case "checkbox":
			case "radio":
				if (theelement.checked != theelement.defaultChecked) return (true);
				break;
			case "select-one":
				if (!theelement.options[theelement.selectedIndex].defaultSelected) return (true);
				break;
			default:
				if (theelement.value != theelement.defaultValue) return (true);
				break;
			}
		}
	}
	return (false);
}
// Graphic button functions
var buttondown = 0;
function dobutton(t,u) {
	var c = t.className.substr(0,t.className.length-1);
	t.className = c+"r";
	t.onmouseover = function (e) {t.className = c+(buttondown ? "a" : "r")}
	t.onmouseout = function (e) {t.className = c+"n"}
	t.onmousedown = function (e) {t.className = c+"a"; buttondown = 1; prevdragstart(e)}
	if (u.indexOf("javascript:")) t.onmouseup = function (e) {var c2 = t.className; t.className = c+"r"; buttondown = 0; if (c2.substr(c.length,1) == "a") location = u};
	else t.onmouseup = function (e) {var c2 = t.className; t.className = c+"r"; buttondown = 0; if (c2.substr(c.length,1) == "a") eval(u.substr(11,1000))};
}
function graphicbuttonsub(name,u,disable) {
	if (disable) return ("<div class="+name+"d onmousedown=prevdragstart(event)></div>");
	return ("<div class="+name+"n onmouseover=\"dobutton(this,'"+u.replace(/'/g,"\'")+"')\"></div>");
}
function navbar(f,p,last) {
	var navtext = "";
	if (buttongraphicstyle) {
		return (graphicbuttonsub("first","javascript:"+f+"(0)",!p)+"&nbsp;"+graphicbuttonsub("prev","javascript:"+f+"("+(p-1)+")",!p)+"&nbsp;"
			+graphicbuttonsub("next","javascript:"+f+"("+(p+1)+")",p >= last)+"&nbsp;"+graphicbuttonsub("last","javascript:"+f+"("+last+")",p >= last));
	}
	if (p) navtext = '<a href="javascript:'+f+'(0)">First</a>&nbsp;|&nbsp;<a href="javascript:'+f+'('+(p-1)+')">Prev</a>&nbsp;|&nbsp;';
	else navtext = '<a href=javascript:void(0) class=nolink>First&nbsp;|&nbsp;Prev</a>&nbsp;|&nbsp;';
	if (p < last) return (navtext+'<a href="javascript:'+f+'('+(p+1)+')">Next</a>&nbsp;|&nbsp;<a href="javascript:'+f+'('+last+')">Last</a>');
	return (navtext+"<a href=javascript:void(0) class=nolink>Next&nbsp;|&nbsp;Last</a>");
}
function undimbutton() {
	if (oldbuttontext != "") {
		buttonobj.innerHTML = oldbuttontext;
		buttonobj.disabled = false;
		oldbuttontext = "";
	}
}
function dimbutton(theobj) {
	if (theobj.disabled) return;
	buttonobj = theobj;
	buttonobj.disabled = true;
	oldbuttontext = buttonobj.innerHTML;
}
function donewpage(theobj,theurl) {
	dimbutton(theobj);
	document.location = theurl;
}
var submitlabel = {};
function savesubmit(name,label) {
	var e;
	submitlabel[name] = label;
}
function dosubmit(myform) {
	if (iphoneapp) return (true);
	if (!myform) myform = document.theform;
	buttonobj = myform.thesubmit;
	if (buttonobj.disabled) return (false);
	buttonobj.disabled = true;
	oldbuttontext = buttonobj.innerHTML;
	buttonobj.innerHTML = submitlabel[typeof myform.name == "string" ? myform.name : "theform"];
	return (true);
}
function potentialhandler(err,param,str) {
	if (!err) {
		str = trim(str);
		var res = str.split(String.fromCharCode(1));
		if (res.length == 2) {
			if (res[1] != "") myalert(res[1]);
			if (res[0] == "result") showhidelayer("potential"+param,false);
		}
	}
}
function ignorepotential(id) {
	geturl("potentialadajax.cfm?action=ignore&id="+id,potentialhandler,id,1);
}
function addpotential(id,name) {
	geturl("potentialadajax.cfm?action=add&id="+id+"&name="+encodeURIComponent(name),potentialhandler,id,1);
}
function getthreemore() {
	geturlintoelement("potentialadajax.cfm?action=refresh&id=0","replacepotential",1);
}
function setmenutab(t,select,hilight) {
	var suffix = select ? "on" : "off";
	var beginsuffix = suffix+(hilight ? "hilight" : "");
	if (t) {
		document.getElementById("mt"+t+".1").className = "begin"+beginsuffix
		document.getElementById("mt"+t+".2").className = "middle"+suffix;
		document.getElementById("mt"+t+".3").className = "end"+suffix;
	}
}
function selectimage(fieldname,i,id) {
	var priori = document.theform[fieldname].value;
	var thestyle;
	if (priori != 0) {
		thestyle = document.getElementById(fieldname+priori).style;
		thestyle.opacity = 0.75;
		thestyle.backgroundColor = "white";
	}
	document.theform[fieldname].value = i;
	thestyle = document.getElementById(fieldname+i).style;
	thestyle.opacity = 1.0;
	thestyle.backgroundColor = "blue";
	return (false);
}
function showhidelayer(thelayer,visibility) {
	thelayer = thelayer.split(",");
	for (var i = 0; i < thelayer.length; i++) {
		document.getElementById(thelayer[i]).style.display = visibility ? '' : 'none';
	}
}
function myalert(message) {
	alert(message);
}
function myconfirm(message,url) {
	if (confirm(message)) {
		if (!url.indexOf('javascript:')) eval(url);
		else window.location = url;
	}
}
function dump(x,maxlev,lev) {
	var e;
	var s = "";
	if (!lev) lev = 0;
	if (typeof maxlev == "undefined") maxlev = 2;
	var indent = "";
	while (indent.length < lev) indent += " ";
	if (lev > maxlev) return (indent+"Too deep!!!\r");
	for (var i in x) {
		try {
		if (typeof x[i] == "object") s += indent+i+":\r"+dump(x[i],maxlev,lev+1);
		else if (typeof x[i] == "function" || typeof x[i] == "undefined") s += indent+i+": "+typeof x[i]+"\r";
		else if (x[i].toString().length < 30) s += indent+i+": "+x[i].toString()+"\r";
		else s += indent+i+": "+x[i].toString().substr(0,30)+"...\r";
		} catch (e) {
			s += indent+i+": Error on "+(typeof x[i])+"\r";
		}
	}
	if (!lev) myalert(s);
	return (s);
}
var iphonepagexoffset,iphonepageyoffset;
function restorescroll() {
	window.scrollTo(iphonepagexoffset,iphonepageyoffset);
}
function closefullsize() {
	document.getElementById("fullsizeid").innerHTML = "";
	showhidelayer("pgcontid",true);
	setTimeout(restorescroll,50);
}
function number3(num) {
	num = ""+num;
	while (num.length < 3) num = "0"+num;
	return (num);
}
function fixfirstname(firstname) {
	if (firstname.length > 120) {
		firstname = "<span class=small style='white-space: nowrap; '>"+firstname.substr(0,11)+"&hellip;</span>";
	}
	else {
		var fna = firstname.split(" ");
		for (var i = 0; i < fna.length; i++) {
			if (fna[i].length > thumbnailnamelimit) {
				if (firstname.indexOf(" ") < 0 && firstname.length > 14) firstname = "<span class=small>"+firstname.substr(0,13)+"&hellip;</span>";
				else firstname = "<span class=small>"+firstname+"</span>";
				break;
			}
		}
	}
	return (firstname);
}
function getthumbnailurl(id,photoid) {
	if (photoid == "*") return (imageserver+"/ph/nophotobig.gif");
	if (photoid == "!") return (imageserver+"/ph/unsafephotobig.gif");
	if (photoid == "?") return (imageserver+"/ph/newphotobig.gif");
	return (imageserver+"/ph/"+number3(Math.floor(id/8192)%256)+"/"+number3(Math.floor(id/32)%256)+"/"+id+"-"+photoid+"BCT.jpg");
}
function getthumbnailimg(id,photoid) {
	var imageurl = getthumbnailurl(id,photoid);
	if (thumbnailcornerradius) return ("<div class=tcs style=\"background-image: url("+imageurl+") !important\"></div>");
	return ("<img src="+imageurl+">");
}
function getphotourl(id,photoid,tt) {
	return (imageserver+"/ph/"+number3(Math.floor(id/8192)%256)+"/"+number3(Math.floor(id/32)%256)+"/"+id+"-"+photoid+tt+".jpg");
}
function openmisc(thehtml,url,part2) {
	if (!part2) {
		iphonepagexoffset = window.pageXOffset;
		iphonepageyoffset = window.pageYOffset;
		showhidelayer("pgcontid",false);
	}
	thehtml = "<div style='position:absolute; top: 0; left: 0; height: 476px; text-align:center; width: 100%; height: 100%; background-color: white'>"+thehtml;
	thehtml += "</div>";
	if (!url) thehtml += "<div style='position:absolute; top: 0; left: 0; height: 476px; text-align:left'><a href=javascript:closefullsize()><img src="+imageserver+"/iphone/close.png width=26></a></div>";
	document.getElementById("fullsizeid").innerHTML = thehtml;
	if (url) geturl(url,openmisccomplete,0,1);
	window.scrollTo(0,iphone);
}
function openmisccomplete(err,param,str) {
	if (!err) openmisc(str,null,true);
	else closefullsize();
}
function viewfullsize(id,photoid,ps,titletype,width,height) {
	var thewindow = "";
	if (iphone) {
		id -= 100000000*Math.floor(id/100000000);
		photoid = String.fromCharCode((photoid.charCodeAt(0)%32)+64)
		var thehtml = "<img src="+getphotourl(id,photoid,ps);
		if (width > 320) thehtml += " width=100%";
		thehtml += ">";
		openmisc(thehtml,null);
		return;
	}
	thewindow = window.open('viewfullsize.cfm?id='+id+'&photoid='+photoid+'&ps='+ps+'&titletype='+titletype+'&w='+width+'&h='+height,'VFS'+Math.floor(Math.random()*1000000),
		'width='+width+',height='+height+',resizable=no,scrollbars=no');
	thewindow.focus();
}
function opensendmessage(id) {
	window.open("sendmessage.cfm?pane=1&id="+id,"","screenx=30,screeny=30,top=30,left=30,height=450,width=620,directories=no,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no");
	return (false);
}
function startic(id,usejschat) {
	window.open('ic.cfm?strDestinationMemberID='+id+'&start=1&usejschat="+usejschat+"&revalidation='+revalidation,'ICWindow2_'+memberid+'_'+id,
		'width='+imwindowwidth+',height='+imwindowheight+',toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=0');
}

function openic(id,membername,alertissued) {
	var thewindow;
	
	thewindow = window.open('ic.cfm?strDestinationMemberID='+id+'&start=0&revalidation='+revalidation,'ICWindow_'+memberid+'_'+id,
		'width='+imwindowwidth+',height='+imwindowheight+',toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=0');
	if (thewindow == null && !alertissued) {
		geturl("alertissued.cfm?m1="+id+"&m2="+memberid,null,0,0);
		myalert("Your popup blocker stopped an Instant Message window from "+membername+".\n\nPlease disable it if you want to use Instant Messages.");
	}
}
function refreshinboxnow() {
	location = "messages.cfm?folder=0";
}
function handlemsg(msg) {
	var id = msg.split(",")[0];
	msg = msg.substring(id.length+1,msg.length);
	id *= 1;
	if (!id) myalert(msg);
	else if (id <= 3) {
		if (iphone) {
			msg = msg.replace(/<[^>]*>/g,"");
			if (msg != "&nbsp;") {
				if (id == 3) myalert(msg);
				else {
					if (refreshinbox) {
						myalert(msg);
						setTimeout(refreshinboxnow,1000);
					}
					else {
						msg += ". View message"+(id == 2 ? "s?" : "?");
						myconfirm(msg,"messages.cfm");
					}
				}
			}
		}
		else if (havenewmsgid) {
			document.getElementById("newmsgid").innerHTML = "<!-- -->"+msg;
			if (id <= 2) {
				setmenutab(messagetab,onmsgtab,1);
				if (refreshinbox) setTimeout(refreshinboxnow,3000);
			}
		}
	}
	else if (id == 99) eval(msg);
	else if (id == 999) location = 'logoff.cfm';
	else myalert("Unknown msg: "+id+": "+msg);
}
function handlesnd(snd) {
	if (iphoneapp) playsound(snd);
	else if (frames.playframe) frames.playframe.location.href = "playsound.cfm?thesnd="+encodeURIComponent(snd);
}
// Stuff for resizing imgs in user HTML
function imgmaxsize(theobj,maxw,maxh) {
	var img = new Image();
	img.src = theobj.src;
	if (!maxh || img.height <= maxh) {
		if (theobj.width > maxw) theobj.width = maxw;
	}
	else if (!maxw || img.width <= maxw) {
		if (theobj.height > maxh) theobj.height = maxh;
	}
	else if (maxw/img.width < maxh/img.height) theobj.width = maxw;
	else theobj.height = maxh;
}
var resizearr = new Array();
function setupimgresize(idlist) {
	var theids = idlist.split(",");
	for (var i = 0; i < theids.length; i++) {
		resizearr[resizearr.length] = theids[i];
		resizearr[resizearr.length] =  theids[i].split(".")[2];
	}
}
function doimgresize() {
	for (var i = 0; i < resizearr.length; i += 2) {
		var theimg = document.getElementById(resizearr[i]);
		var maxwidth = resizearr[i+1];
		// if (memberid == 1) myalert(theimg.width+"\r"+getObjectProperties(theimg));
		if (theimg && theimg.width > maxwidth) theimg.width = maxwidth;
		// if (theimg.clientWidth > maxwidth) theimg.clientWidth = maxwidth;
		// if (memberid == 1) myalert("Now: "+theimg.width);
	}
}
// Stuff for polling
var maxloops = 2000;
var windowkey = Math.random();
var lastmessageid = 0;
function pollinghandler(err,param,str) {
	var membername = '';
	var alertissued = 0;
	try {
		var arr = str.split("&");
		maxloops--;
		for (var i = 0; i < arr.length; i++) {
			if (arr[i] != "") {
				param = arr[i].split("=");
				if (param[1] != "") {
					var theparam = decodeURIComponent(param[1]);
					if (param[0] == "delay" && maxloops >= 0) setTimeout(startpollingsub,1000*theparam);
					else if (param[0] == "icopen" && theparam != 0) openic(parseInt(theparam),membername,alertissued);
					else if (param[0] == "fail") {}
					else if (param[0] == "msg") handlemsg(theparam);
					else if (param[0] == "snd") handlesnd(theparam);
					else if (param[0] == "name") membername = theparam;
					else if (param[0] == "alertissued") alertissued = parseInt(theparam);
					else if (param[0] == "messageid") lastmessageid = theparam;
				}
			}
		}
	} catch (e) {
	}
}
var icpollenabled = 1;
function seticpolling(st) {
	icpollenabled = st;
}
function startpollingsub() {
	if (icpollenabled) geturl("icstatus.cfm?id="+memberid+"&wkey="+windowkey+"&messageid="+lastmessageid,pollinghandler,0,0);
}
function startpolling(canpoll) {
	if (!canpoll) maxloops = 1;
	startpollingsub();
}
function openfriends() {
	window.open('friendsonline.cfm','friendsonline',
		'width='+fronlinewidth+',height='+fronlineheight+',toolbar=0,directories=0,menubar=0,status=0,location=0,resizable=1');
}
function opentip(url,w,h) {
	if (url.indexOf("?") >= 0) url += "&";
	else url += "?";
	url += "revalidation="+revalidation+"&pane=1&paneheader=1&panewidth="+w;
	if (iphone) {
		openmisc("<br><br><br><br><br><br><img src="+imageserver+"/pieces/loading.gif>Loading...",url);
		return;
	}
	window.open(url,null,"screenx=30,screeny=30,top=30,left=30,width="+w+",height="+h+",toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=0");
}
function openwhatsthis(url,w,h) {
	opentip(url,w,h);
}
function opencertified(id,w,h) {
	if (iphone) {
		opentip("certphoto.cfm?id="+id,w,h);
		return;
	}
	var url = "certifiedmember.cfm?id="+id+"&revalidation="+revalidation+"&pane=1&paneheader=3&panewidth="+w;
	window.open(url,null,"screenx=30,screeny=30,top=30,left=30,width="+w+",height="+h+",toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=0");
}
function openprofilepane(id) {
	var url = 'viewprofile.cfm?id='+id+'&pane=1&revalidation='+revalidation;
	if (iphone) {
		openmisc("<br><br><br><br><br><br><img src="+imageserver+"/pieces/loading.gif>Loading...",url);
		return;
	}
	var thewindow = window.open(url,'VPR'+Math.floor(Math.random()*1000000),'width='+panewidth+',height='+paneheight);
	thewindow.focus();
}
function groupelim(groupid) {
	new Image().src = "groupelim.cfm?groupid="+groupid+"&revalidation="+revalidation;
	showhidelayer("groupad"+groupid,0);
}
function getObjectProperties(object) {
	var result = '';
	for (var property in object) {
		try {
			result += property+': '+object[property]+'\r\n';
		} catch (e) {
			result += property+': ???\r\n';
		}
	}
	return result;
}
function gethttpobj() {
	var e;
	if (window.XMLHttpRequest) return (new XMLHttpRequest());
	else if (window.ActiveXObject) {
		try {
			return (new ActiveXObject("Msxml2.XMLHTTP"));
		} catch (e) {
			try {
				return (new ActiveXObject("Microsoft.XMLHTTP"));
			} catch (e) {
			}
		}
	}
	return (false);
}
function xhandler(x,f,param,ftype,url) {
	if (x.readyState == 4) {
		var err = (x.status == 200 || x.status == 304 || typeof x.status == "undefined") ? 0 : x.status;
		if (x.status == 0 && ftype > 0 && admin) myalert("Response 0!!! Status: "+x.statusText);
		else if (err && ftype > 0) myalert(x.statusText+" (#"+err+"). Check your network connection and try again in a moment.");
		if (typeof f == "function") {
			if (Math.abs(ftype) == 2 && !err) {
				var res = trim(x.responseText).split(String.fromCharCode(1));
				if (res[0] == "*logon*") myalert("You must log on to do this.");
				else if (res[0] != "") {
					var errpos = res[0].indexOf("<!--[[Error]]");
					if (errpos > 0) {
						res[0] = res[0].substr(errpos+13,100000);
						errpos = res[0].indexOf("-->");
						if (errpos > 0) res[0] = "CF Error in "+location.href.split("?")[0]+": "+res[0].substr(0,errpos).replace(/<br>/g,"\r");
					}
					myalert(res[0]);
				}
				f(err,param,res);
			}
			else f(err,param,x.responseText);
		}
	}
}

// NOTE: geturl f = function, if function has parameters use function(){callwhendone(theid,thetype)} - example below
// geturl("page.cfm",function(){callwhendone(theid,thetype)},0,0);
// ftype: 0: Normal (no error handling), 1: $ returned, 2: Array returned (elem 0 is error string or *logon*) [gotten from string separated by Chr(1)]
// ftype <= 0 doesn't handle network errors, > 0 gives alert
function geturl(url,f,param,ftype,sync) {
	var x = gethttpobj();
	if (x) {
		if (typeof ftype == "undefined") ftype = 0;
		if (typeof sync == "undefined") sync = false;
		x.onreadystatechange = function () {
			xhandler(x,f,param,ftype,url);
		}
		if (url.length <= 1000) {
			x.open("GET",url,!sync);
			x.send(null);
		} else {
			var pos = url.indexOf("?");
			var params = url.substr(pos+1,url.length);
			url = url.substr(0,pos);
			x.open("POST",url,!sync);
			x.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			if (memberid != 1) {
				x.setRequestHeader("Content-length",params.length);
				x.setRequestHeader("Connection","close");
			}
			x.send(params);
		}
	}
	return (x);
}
var submitdatalen = 0;	// For debugging purposes
function mysubmitform(formname,action,f,param,ftype,sync) {
	var myform = document.getElementsByName(formname).item(0);
	var data = "";
	var fulldump = formname.indexOf("iphonesavestate.cfm") >= 0;
	for (var i = 0; i < myform.elements.length; i++) {
		var theelement = myform.elements[i];
		if (theelement.name != "") {
			switch (theelement.type) {
			case "reset":
			case "submit":
			case "button":
				break;
			case "select":
				data += theelement.name+"="+encodeURIComponent(theelement.options[theelement.selectedIndex].value)+"&";
				break;
			case "checkbox":
			case "radio":
				if (fulldump) {
					data += theelement.name+"="+(theelement.checked*1)+"&";
					break;
				}
				if (!theelement.checked) break;
			default:
				data += theelement.name+"="+encodeURIComponent(theelement.value)+"&";
				break;
			}
		}
	}
	submitdatalen = data.length;
	var sep = action.indexOf("?") < 0 ? "?" : "&";
	if (action != "") return (geturl(action+sep+data,f,param,ftype,sync));
	return (geturl(myform.action+sep+data,f,param,ftype,sync));
}
function putintoelement(err,id,str) {
	if (!err) document.getElementById(id).innerHTML = "<!-- -->"+str;
}
function geturlintoelement(url,id,ftype,sync) {
	geturl(url,putintoelement,id,ftype,sync);
}
function submitformintoelement(formname,action,id,ftype,sync) {
	mysubmitform(formname,action,putintoelement,id,ftype,sync);
}
var jsonpollarray = new Array();
function restartjsonpoll(jsoncallbackid) {
	var theobj = jsonpollarray[jsoncallbackid];
	theobj.js = document.createElement("script");
	theobj.js.setAttribute("type","text/javascript");
	theobj.js.setAttribute("src",theobj.url+"&jsonrnd="+Math.random());
	document.body.appendChild(theobj.js);
}
function jsoncallback(str,jsoncallbackid) {
	var theobj = jsonpollarray[jsoncallbackid];
	document.body.removeChild(theobj.js);
	theobj.js = null;
	if (theobj.interval >= 0) {
		if ((typeof theobj.f) == "function") theobj.f(0,0,str);
		if (theobj.interval) setTimeout("restartjsonpoll("+jsoncallbackid+")",theobj.interval);
	}
	if (theobj.interval <= 0) jsonpollarray[jsoncallbackid] = null;
}
function startjsonpoll(url,f,interval) {
	var theobj = new Object();
	var jsoncallbackid = jsonpollarray.length;
	jsonpollarray[jsoncallbackid] = theobj;
	theobj.url = url+(url.indexOf("?") >= 0 ? "&" : "?")+"jsoncallbackid="+jsoncallbackid;
	theobj.f = f;
	theobj.interval = interval;
	restartjsonpoll(jsoncallbackid);
	return (jsoncallbackid);
}
function stopjsonpoll(jsoncallbackid) {
	jsonpollarray[jsoncallbackid].interval = -1;
}
function getjson(url,f) {
	startjsonpoll(url,f,0);
}
function insertad(adlocation) {
	var divid = "addiv"+adlocation;
	document.write("<div id="+divid+"></div>");
	geturlintoelement("adserver.cfm?v=2&adlocation="+adlocation+"&referrer="+encodeURIComponent(document.referrer)+"&theurl="+encodeURIComponent(document.URL),divid,0);
}
var selectedstate = "";
function recreatemenu(themenu,str,theindex) {
	var strarray = str.split(",");
	
	themenu.options.length = 0;
	themenu.selectedIndex = 0;
	for (var i = 0; i < strarray.length; i += 2) {
		themenu.options[i/2] = new Option(strarray[i],strarray[i+1]);
		if (selectedstate == strarray[i+1]) {
			themenu.selectedIndex = i/2;
		}
	}
	delete strarray;
	selectedstate = "";
}
function switchcountry(countrypopup,statepopup,theindex) {
	country = countrypopup.options[countrypopup.selectedIndex].value;
	if (country == "United States") recreatemenu(statepopup,usmenu,theindex);
	else if (country == "Canada") recreatemenu(statepopup,canadamenu,theindex);
	else if (country == "Australia") recreatemenu(statepopup,australiamenu,theindex);
	else recreatemenu(statepopup,othermenu,theindex);
}
function createstatemenu(themenu,countries,state) {
	var strarray;
	countries = countries.split(",");
	themenu.options.length = 0;
	themenu.selectedIndex = 0;
	var k = 0;
	for (var j = 0; j < countries.length; j++) {
		if (countries[j] == "United States") strarray = usmenu.split(",");
		else if (countries[j] == "Canada") strarray = canadamenu.split(",");
		else if (countries[j] == "Australia") strarray = australiamenu.split(",");
		for (var i = 2; i < strarray.length; i += 2) {
			themenu.options[k] = new Option(strarray[i],strarray[i+1]);
			if (strarray[i].substr(0,1) == "-") themenu.options[k].disabled = true;
			if (state == strarray[i+1]) themenu.selectedIndex = k;
			k++;
		}
		if (j != countries.length-1) {
			themenu.options[k] = new Option("-----------------","-");
			themenu.options[k].disabled = true;
			k++;
		}
	}
	delete strarray;
	selectedstate = "";
}
var usmenu = "-- Please Choose a State --,N/A,Alabama,AL,Alaska,AK,Arizona,AZ,Arkansas,AR,California,CA,Colorado,CO,Connecticut,CT,Delaware,DE,District of Columbia,DC,Florida,FL,Georgia,GA,Hawaii,HI,Idaho,ID,Illinois,IL,Indiana,IN,Iowa,IA,Kansas,KS,Kentucky,KY,Louisiana,LA,Maine,ME,Maryland,MD,Massachusetts,MA,Michigan,MI,Minnesota,MN,Mississippi,MS,Missouri,MO,Montana,MT,Nebraska,NE,Nevada,NV,New Hampshire,NH,New Jersey,NJ,New Mexico,NM,New York,NY,North Carolina,NC,North Dakota,ND,Ohio,OH,Oklahoma,OK,Oregon,OR,Pennsylvania,PA,Rhode Island,RI,South Carolina,SC,South Dakota,SD,Tennessee,TN,Texas,TX,Utah,UT,Vermont,VT,Virginia,VA,Washington,WA,West Virginia,WV,Wisconsin,WI,Wyoming,WY,-----------------,-,Puerto Rico,PR,Virgin Islands,VI";
var canadamenu = "-- Please Choose a Province --,N/A,Alberta,AB,British Columbia,BC,Manitoba,MB,New Brunswick,NB,Newfoundland,NF,Northwest Territory,NT,Nova Scotia,NS,Nunavut,NU,Ontario,ON,Prince Edward Island,PE,Quebec,QC,Saskatchewan,SK,Yukon,YT";
var australiamenu = "-- Please Choose a State --,N/A,Australian Capital Territory,!ACT,New South Wales,!NSW,Northern Territory,!NT,Queensland,!QLD,South Australia,!SA,Tasmania,!TAS,Victoria,!VIC,Western Australia,!WA";
var othermenu = "Not Applicable,N/A";

function hasstates(country) {
	return (",United States,Canada,Australia,".indexOf(","+country+",") >= 0);
}
function trim(str) {
	str = str.replace(new RegExp(String.fromCharCode(160),"g")," ");
	return str.replace(/^\s+|\s+$/g,"");
}
function fulltrim(str) {
	var oldlen = 0;
	str = str.replace(new RegExp(String.fromCharCode(160),"g")," ");
	while (oldlen != str.length) {
		oldlen = str.length;
		str = str.replace(/  /g," ");
	}
	return trim(str);
}
function left(str,n) {
	if (n <= 0) return "";
	else if (n > String(str).length) return str;
	return String(str).substring(0,n);
}
function right(str,n) {
	if (n <= 0) return "";
	else if (n > String(str).length) return str;
	var iLen = String(str).length;
	return String(str).substring(iLen,iLen-n);
}
function mid(str,start,n) {
    if (start < 0 || n < 0) return "";
    var iEnd, iLen = String(str).length;
    if (start + n > iLen || n == 0) iEnd = iLen;
    else iEnd = start + n;
    return String(str).substring(start,iEnd);
}
function pluralize(noun,count) {
	var nounsplit;
	nounsplit = noun.split(',');  //noun[0], noun[1]

	if (nounsplit.length == 2) {
		if (count == 1) return (nounsplit[0]);
		return (nounsplit[1]);
	}
	if (count == 1) return (noun);
	//*** right and left functions are in widgetjs.cfm ***	
	if (right(noun,1) == 'y' && noun != 'day') return (left(noun,noun.length-1)+'ies');
	if (right(noun,1) == "s")  return (noun+"es");
	return (noun+'s');
}
function Browser() {
	var ua,s,i;
	this.isIE = false;
	this.isNS = false;
	this.version = null;
	ua = navigator.userAgent;
	s = "MSIE";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isIE = true;
		this.version = parseFloat(ua.substr(i+s.length));
		return;
	}
	s = "Netscape6/";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;

		this.version = parseFloat(ua.substr(i+s.length));
		return;
	}
	// Treat any other "Gecko" browser as NS 6.1
	s = "Gecko";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = 6.1;
		return;
	}
}
var whatsupfunction = null;
function putintostatus(err,param,str) {
	if (!err) {
		document.getElementById("mstatus2").innerHTML = "<!-- -->"+str;
		if (whatsupfunction) whatsupfunction();
	}
}
function updatestatus(opcode,firstname) {
	var status = document.statusform.status.value;
	if (opcode == 1 && status == "") status = "";
	if (opcode == -1) {
		showhidelayer("mstatus1",true);
		document.statusform.status.focus();
		document.statusform.status.select();
	} else if (opcode == 1) {
		// Update
		status = status.replace(/^\s+|\s+$/g,"");
		if (status == "is") status = "";
		if (status != "" && status.substring(status.length-1).search(/[.!?]/) < 0) status += ".";
		geturl("setstatus.cfm?revalidation="+revalidation+"&fn="+encodeURIComponent(firstname)+"&status="+encodeURIComponent(status),(document.getElementById("mstatus2") ? putintostatus : null),0,1);
		document.statusform.status.value = "";
		showhidelayer("mstatus1",false);
	} else if (opcode == 0) {
		showhidelayer("mstatus1",false);
		document.statusform.status.value = "is ";
	}
}

// ------------------- ui.js
// Utility routines
function setopacity(id,opacity) {
	var theobj = document.getElementById(id);
	if (typeof document.body.style.opacity == "undefined") {
		try {
			theobj.filters.alpha.opacity = opacity*100;
		} catch (e) {}
		theobj.style.filter = "alpha(opacity=50)";
		theobj.style.opacity = .5;
	}
	else theobj.style.opacity = opacity;
}
// Get window size {width, height}
function getwindowsize() {
  var w = 100000, h = 100000;
  if (typeof window.innerWidth == 'number') {
		w = window.innerWidth;
		h = window.innerHeight;
  }
  if (document.documentElement && document.documentElement.clientWidth) {
		w = Math.min(w,document.documentElement.clientWidth);
		h = Math.min(h,document.documentElement.clientHeight);
	}
	return ({width:w, height:h});
}
// Get window scroll {x, y}
function getwindowscroll() {
  if (typeof window.pageYOffset == "number") {
    // Netscape compliant
    return ({x:window.pageXOffset, y:window.pageYOffset});
  } else if (isie) {
    // IE6 standards compliant mode
    return ({x:document.documentElement.scrollLeft+document.body.scrollLeft, y:document.documentElement.scrollTop+document.body.scrollTop});
  } else {
    // DOM compliant
    return ({x:document.body.scrollLeft, y:document.body.scrollTop});
  }
}
// Get element position on page {top, left, width, height}
function getelementinfo(e) {
	e = document.getElementById(e);
	var info = {left:0, top:0, width:e.offsetWidth, height:e.offsetHeight};
	do {
		info.left += e.offsetLeft;
		info.top += e.offsetTop;
	} while (e = e.offsetParent);
	return (info);
}
// Gets the cursor location from an event {x, y}
function getcursorxy(e) {
	if (document.attachEvent) {
		return ({x:window.event.clientX+document.documentElement.scrollLeft+document.body.scrollLeft,
			y:window.event.clientY+document.documentElement.scrollTop+document.body.scrollTop});
	} else if (window.Touch) {
		return ({x:e.targetTouches[0].clientX+window.scrollX, y:e.targetTouches[0].clientY+window.scrollY});
	}
	return ({x:e.clientX+window.scrollX, y:e.clientY+window.scrollY});
}

// Key handlers
var keyfunction = null;	// Prior key handler
var documentkeyhandler = document.onkeydown;
function keyhandler(e) {
	var e  = e ? e : (event ? event : null);
	var node = e.target ? e.target : (e.srcElement ? e.srcElement : null);
	if (!node.name) {
		if (!keyfunction(node,e.keyCode)) return (false);
	}
	if (documentkeyhandler) return (documentkeyhandler(e));
	return (true);
}

function capturekeys(keyf) {
	var oldkeyf = document.onkeydown;
	keyfunction = keyf;
	document.onkeydown = keyf ? keyhandler : documentkeyhandler;
	return (oldkeyf);
}

// Routines for handling menus
var menuh = {
	capturing:0,		// True if we're capturing mouse events
	dragging:0,			// True while we're dragging
	cursorstart:0,			// Start location of click
	bigmove:0,			// True if we've moved by more than 4 pixels since the click
	headclick:0,		// True if down click was on the menu head
	curmenuid:null,	// id of the open menu (null if none)
	parentid:null,		// id of open menu's parent
	curmenuitem:0,		// item number of currently selected item in current menu
	keyhandler:null	// Saved key handler
}
function selectmenuitem(menuid,item,select) {
	var menuitemobj = document.getElementById(menuid+"."+item);
	if (select && menuitemobj.className == "") {
		menuitemobj.className = "selected";
		menuh.curmenuitem = item;
	}
	else {
		if (!select && menuitemobj.className == "selected") menuitemobj.className = "";
		if (menuh.curmenuitem == item) menuh.curmenuitem = 0;
	}
}
function enablemenuitem(menuid,item,enable) {
	document.getElementById(menuid+"."+item).className = enable ? "" : "disabled";
}
function domenudrag(event) {
	if (!menuh.bigmove) {
		var curxy = getcursorxy(event);
		menuh.bigmove = Math.abs(curxy.x-menuh.cursorstart.x) >= 4 || Math.abs(curxy.y-menuh.cursorstart.y) >= 4
	}
	cancelbubble(event);
}
function startmenudrag(event,clickonhead) {
	// Capture mousemove and mouseup events on the page
	menuh.headclick = clickonhead;
	menuh.bigmove = 0;
	menuh.dragging = 1;
	menuh.cursorstart = getcursorxy(event);
	if (!menuh.capturing) {
		if (document.attachEvent) document.attachEvent("ondblclick",ignoredblclick);
		captureevents(document,domenudrag,stopmenudrag);
		menuh.capturing = 1;
	}
	domenudrag(event);
}
function closemenu(menuitem) {
	if (menuh.curmenuid) {
		// Stop animation and hide it!
		if (menuanimation) showhidelayeranimstop(menuh.curmenuid);
		else showhidelayer(menuh.curmenuid,0);
		var f = document.getElementById(menuh.curmenuid+"f").value.split(",");
		eval(f[0]+"('"+menuh.parentid+"','"+(menuitem == "close" ? "close" : f[menuitem])+"')");
		menuh.curmenuid = null;
	}
	// Stop capturing mousemove and mouseup events
	if (menuh.capturing) {
		if (document.attachEvent) document.detachEvent("ondblclick",ignoredblclick);
		releaseevents(document,domenudrag,stopmenudrag);
		menuh.capturing = 0;
	}
	menuh.curmenuitem = 0;
	document.onkeydown = menuh.keyhandler;
}
function menuescape(node,keycode) {
	if (keycode == 27 && !menuh.dragging) closemenu("close");
	return (false);
}
function stopmenudrag(event) {
	if (menuh.curmenuitem) closemenu(menuh.curmenuitem);
	else if (!menuh.headclick || menuh.bigmove && !iswindows) closemenu("close");
	menuh.dragging = 0;
}
function ignoredblclick(event) {
	cancelbubble(event);
}
function openmenu(event,parentid,position) {
	var menuid = "*"+parentid;
	if (menuh.curmenuid) {
		if (menuh.curmenuid == menuid) {
			closemenu("close");
			return (false);
		}
		closemenu("close");
	}
	var f = document.getElementById(menuid+"f").value.split(",");
	eval(f[0]+"('"+parentid+"','open')");
	var menuobj = document.getElementById(menuid);
	var info = getelementinfo(parentid);
	var windowwidth = getwindowsize().width;
	var scrollx = getwindowscroll().x;
	var menuleft = info.left;

	menuobj.style.top = (info.top+info.height)+"px";
	position = position.toLowerCase().substr(0,1);
	setopacity(menuid,0);
	showhidelayer(menuid,1);
	if (position == "r") menuleft += info.width-menuobj.offsetWidth;
	menuleft = Math.min(menuleft+menuobj.offsetWidth,windowwidth+scrollx)-menuobj.offsetWidth;
	menuleft = Math.max(menuleft,scrollx);
	menuobj.style.left = menuleft+"px";
	if (menuanimation == 2) {
		setopacity(menuid,menuopacity);
		showhidelayeranim(menuid,1,"height",null,0,menuobj.offsetHeight);
	}
	else if (menuanimation) {
		showhidelayeranim(menuid,1,"opacity",null,0,menuopacity);
	}
	else setopacity(menuid,menuopacity);
	menuh.curmenuid = menuid;
	menuh.parentid = parentid;
	startmenudrag(event,1);
	menuh.keyhandler = capturekeys(menuescape);
	return (false);
}
function createmenu(parentid,position) {
	var parentobj = document.getElementById(parentid);
	parentobj.onmousedown = function (e) {openmenu(e,parentid,position)};
	parentobj.className += " menucursor";
}
var curdialogid = null;
var olddialogkeyhandler = null;
var savecontareah = "";
function showdialog(id,show,callback) {
	var contareastyle = document.getElementById("contareaid").style;
	if (show) {
		// Show dialog invisibly so we can get the right height
		setopacity(id,0);
		showhidelayer(id,1);
		var continfo = getelementinfo("contareaid");
		savecontareah = contareastyle.height;
		var coverstyle = document.getElementById("dialogcover").style;
		var dialogstyle = document.getElementById(id).style;
		dialogstyle.top = coverstyle.top = continfo.top+"px";
		dialogstyle.left = coverstyle.left = continfo.left+"px";
		dialogstyle.width = coverstyle.width = continfo.width+"px";
		var maxh = Math.max(continfo.height,getelementinfo(id).height);
		dialogstyle.height = coverstyle.height = maxh+"px";
		//contareastyle.height = maxh+"px";
		iphonepagexoffset = window.pageXOffset;
		iphonepageyoffset = window.pageYOffset;
		window.scrollTo(0,iphone);
	}
	else {
		contareastyle.height = savecontareah;
		setTimeout(restorescroll,50);
	}
	if (dialoganimation) {
		showhidelayeranim("dialogcover",show,"opacity",null,0,dialogopacity);
		showhidelayeranim(id,show,"opacity",callback);
	}
	else {
		setopacity("dialogcover",dialogopacity);
		showhidelayer("dialogcover",show);
		setopacity(id,1);
		showhidelayer(id,show);
		if (callback) callback();
	}
}
function dialogkeys(node,keycode) {
	if (keycode == 27) {
		closedialog();
		return (false);
	}
	return (true);
}
function opendialog(id,callback) {
	curdialogid = id;
	showdialog(id,1,callback);
	olddialogkeyhandler = capturekeys(dialogkeys)
}
function closedialog(callback) {
	if (curdialogid) {
		showdialog(curdialogid,0,callback);
		curdialogid = null;
		document.onkeydown = olddialogkeyhandler;
	}
}
// ------------------- anim.js
function expanddivanimstop(id) {
	var theobj = document.getElementById(id);
	if (theobj.animobj) {
	}
}
function expanddivanim(thetimer) {
	var deltat = new Date().getTime()-thetimer.starttime;
	var maxheight = Math.max(thetimer.theobj.clientHeight,thetimer.height);
	var newheight = maxheight*Math.min(1,deltat/thetimer.duration);
	thetimer.theobj.style.cssText = thetimer.csstext+";height:"+newheight+"px;overflow:hidden";
	if (maxheight == newheight) {
		clearInterval(thetimer.interval);
		thetimer.theobj.style.cssText = thetimer.csstext;
	}
}
function insertandexpand(theobj,beforeobj,duration) {
	var thetimer = new Object();
	thetimer.csstext = theobj.style.cssText+";opacity:1;filter:alpha(opacity=100)";
	theobj.style.cssText = thetimer.oldcsstext+";overflow:hidden;visiblity:hidden;position:absolute;left:-1000px;top:-1000px";
	if (beforeobj) beforeobj.parentNode.insertBefore(theobj,beforeobj.nextSibling);
	var height = theobj.clientHeight;
	if (height) {
		thetimer.theobj = theobj;
		thetimer.height = height;
		thetimer.duration = duration;
		theobj.style.cssText = thetimer.csstext+";height:0;overflow:hidden;display:none";
		thetimer.starttime = new Date().getTime();
		thetimer.interval = setInterval(function () {expanddivanim(thetimer)},50);
	}
	else theobj.style.cssText = thetimer.csstext;
}
function expanddiv(theobj,duration) {
	insertandexpand(theobj,null,duration);
}
function insertdiv(id,str,duration) {
	var beforeobj = document.getElementById(id);
	if (!beforeobj) return (false);
	var newdiv = document.createElement("div");
	newdiv.innerHTML = str;
	insertandexpand(newdiv,beforeobj,duration);
	return (true);
}
function settransitionproperty(id,property,val) {
	if (property == "opacity" || property == "both") setopacity(id,val);
	if (property == "scale" || property == "both") {
		val = Math.max(val,.01);
		document.getElementById(id).style.webkitTransform = "scale("+val+","+val+")";
		document.getElementById(id).style.MozTransform = "scale("+val+","+val+")";
	}
	if (property == "height") {
		document.getElementById(id).style.height = typeof val != "number" ? "" : val+"px";
	}
}
function animstep(animobj) {
	if (animobj.suspend) return;
	animobj.fraction = Math.min((new Date().getTime()-animobj.starttime)/animobj.duration,1);
	animobj.curval = animobj.showhide ? animobj.startval+(animobj.endval-animobj.startval)*animobj.fraction : animobj.endval+(animobj.startval-animobj.endval)*animobj.fraction;
	if (!animobj.webkit) settransitionproperty(animobj.id,animobj.property,animobj.curval);
	//else settransitionproperty(animobj.id,animobj.property,animobj.showhide ? animobj.endval : animobj.startval);
	if (animobj.fraction == 1) {
		clearInterval(animobj.interval);
		animobj.interval = null;
		if (animobj.webkit) animobj.theobj.style.webkitTransition = "";
		if (animobj.property == "height") {
			theobj.style.cssText = animobj.savedcss;
			settransitionproperty(animobj.id,"height","");
		}
		if (!animobj.showhide) showhidelayer(animobj.id,0);
		if (animobj.callback) animobj.callback();
	}
}
function showhidelayeranimstop(id) {
	var theobj = document.getElementById(id);
	if (theobj && theobj.animobj) {
		var animobj = theobj.animobj;
		if (animobj.interval) {
			clearInterval(animobj.interval);
			animobj.interval = null;
		}
		if (animobj.webkit) theobj.style.webkitTransition = "";
		if (animobj.property == "height") theobj.style.cssText = animobj.savedcss;
		showhidelayer(id,0);
		animobj.showhide = 0;
		animobj.fraction = 1;
		animobj.curval = animobj.startval;
		settransitionproperty(id,animobj.property,animobj.property == "height" ? "" : animobj.curval);
		if (animobj.callback) animobj.callback();
	}
}
function showhidelayeranim(id,showhide,property,callback,startval,endval,duration) {
	var theobj = document.getElementById(id);
	var animobj = theobj.animobj ? theobj.animobj : new Object();
	animobj.theobj = theobj;
	animobj.suspend = 1;
	startval = typeof startval == "undefined" ? 0 : startval;
	endval = typeof endval == "undefined" ? 1 : endval;
	duration = typeof duration == "undefined" ? 300 : duration;
	if (animobj.property == property) {
		if (animobj.showhide == showhide) return;
		duration *= animobj.fraction;
		if (showhide) startval = animobj.curval;
		else endval = animobj.curval;
	}
	else {
		animobj.id = id;
		animobj.property = property;
	}
	animobj.duration = duration;
	animobj.showhide = showhide;
	animobj.callback = callback ? callback : null;
	animobj.startval = startval;
	animobj.curval = showhide ? animobj.startval : animobj.endval;
	animobj.endval = endval;
	animobj.fraction = 0;
	
	if (animobj.property == "height") {
		if (!animobj.savedcss) animobj.savedcss = theobj.style.cssText;
		theobj.style.cssText = animobj.savedcss+";overflow:hidden";
	}
	animobj.webkit = 0 && typeof theobj.style.webkitTransition != "undefined" && property != "height";
	if (animobj.webkit) theobj.style.webkitTransition = "";
	theobj.animobj = animobj;
	animobj.suspend = 0;
	settransitionproperty(id,animobj.property,animobj.curval);
	showhidelayer(id,1);
	if (animobj.webkit) theobj.style.webkitTransition = property+" "+duration+"ms linear";
	animobj.starttime = new Date().getTime();
	if (!animobj.interval) animobj.interval = setInterval(function (){animstep(animobj)},33);
}

function ghostobj(theform,theobj,defval) {
	defval += "\t";
	var focusf = function() {
			if (theobj.value === defval) theobj.value = "";
			theobj.style.color = 'black';
		};
	var blurf = function() {
			if (theobj.value == "") theobj.value = defval;
			if (theobj.value === defval) theobj.style.color = '#B2B2B2';
		};
	blurf();
	if (window.attachEvent) {
		theobj.attachEvent('onfocus',focusf);
		theobj.attachEvent('onblur',blurf);
		theform.attachEvent('onsubmit',focusf);
	}
	else {
		theobj.addEventListener('focus',focusf,true);
		theobj.addEventListener('blur',blurf,true);
		theform.addEventListener('submit',focusf,true);
	}
}

function ghost(flist,theform) {
	if (!theform) theform = document.theform;
	flist = flist.split(";");
	for (var i in flist) {
		var item = flist[i].split(",");
		ghostobj(theform,theform[item[0]],item[1]);
	}
}

var curgps,newgps,gpslast,gpsf;
var convertinggps = 0,gpscount = 0,gpsmovecount = 0,qpsconvcount = 0,gpserrcount = 0,gspwatchid = 0;
var geoobj;	// Debug
var geopage = Math.floor(Math.random()*10000);
function geolocconvert(err,param,res) {
	var errtext = "";
	var valid = 0
	qpsconvcount++;
	if (!err) {
		if (res[0] == "") {
			if (res[1]*1 == 0) errtext = res[2];
			else if (res[1]*1 == 1) {
				newgps.loctext = res[2].replace("&","&amp;");
				newgps.loclist = res[3];
				valid = 1;
				if (geoobj) geoobj.innerHTML = "Location: "+res[2];
			}
			else errtext = "Version error: ver="+res[1]+"; len="+res.length;
		}
		else errtext = "CF error: "+res[0];
	}
	else errtext = "Network error #"+err;
	if (errtext != "") {
		newgps.loctext = errtext;
		newgps.loclist = 0+"\t"+errtext;
		valid = admin;
		gpserrcount++;
		if (geoobj) geoobj.innerHTML = "Conversion error: "+errtext;
	}
	if (valid) {
		newgps.qpsconvcount = qpsconvcount;
		newgps.gpserrcount = gpserrcount;
		curgps = newgps;
		if (gpsf) gpsf(curgps);
	}
	convertinggps = 0;
}
function geoloc(q) {
	gpscount++;
	var p = {};
	q = q.coords;
	for (var i in q) p[i] = q[i] == null ? 0 : q[i];
	if (!convertinggps && (!curgps || (p.latitude != curgps.latitude || p.longitude != curgps.longitude || p.accuracy < curgps.accuracy))) {
		if (geoobj) geoobj.innerHTML = "@ "+p.latitude+", "+p.longitude;
		newgps = p;
		newgps.gpscount = gpscount;
		newgps.gpsmovecount = ++gpsmovecount;
		var info = "v3 "+geopage+": "+(!curgps)+" || "+(!convertinggps);
		if (curgps) info += " && ("+(p.latitude != curgps.latitude)+" || "+(p.longitude != curgps.longitude)+" || "+(p.accuracy < curgps.accuracy)+")";
		info = escape(info);
		convertinggps = 1;
		geturl("geonames.cfm?action=record&lat="+p.latitude+"&long="+p.longitude+"&accuracy="+p.accuracy+"&alt="+p.altitude+"&altaccuracy="+p.altitudeAccuracy+"&info="+info,geolocconvert,0,-2);
		gpslast = new Date().getTime();
	}
	else if (new Date().getTime()-gpslast > 30000) {
		geturl("geonames.cfm?action=update",null,0,-2);
		gpslast = new Date().getTime();
	}
	var trkobj = document.getElementById("gpstrkid");
	if (trkobj) trkobj.innerHTML = "("+gpsmovecount+"/"+gpscount+") "+Math.floor(p.latitude*1e6)/1e6+", "+Math.floor(p.longitude*1e6)/1e6+" &plusmn;"+Math.floor(p.accuracy*3.3+.5)+"' ("+Math.floor(p.altitude*3.3+.5)+"'&plusmn;"+Math.floor(p.altitudeAccuracy*3.3+.5)+"')";
}
function xyzs(err,param,str) {
	if (geoobj) geoobj.innerHTML = "0; Err: "+err+"; Str: "+str;
}
function geolocerr(err) {
	switch (err.code) {
	case err.PERMISSION_DENIED:
		if (geoobj) geoobj.innerHTML = "Attempting to deny";
		geturl("setgeolocation.cfm?usegeolocation=0",xyzs,0,1);
		if (iphoneapp) stoplocationupdates();
		else navigator.geolocation.clearWatch(gspwatchid);
		gpsf = null;
		break;
	default:
		if (geoobj) geoobj.innerHTML = "Bad geolocerr code: "+err.code;
		break;
	}
}
function locationtrack(f) {
	geoobj = document.getElementById("geoerrid");
	if (f) gpsf = f;
	if (iphoneapp) {
		if (memberid == -1) alert("Starting geo 1");
		startlocationupdates("geoloc","geolocerr");
		if (memberid == -1) alert("Starting geo 2");
		return (true);
	}
	else if (navigator && navigator.geolocation) {
		if (!gspwatchid) gspwatchid = navigator.geolocation.watchPosition(geoloc,geolocerr,{enableHighAccuracy: true});
		return (true);
	}
	return (false);
}

