var browser='good';
var curstat=0;
var statAr=new Array('Available','Away');
if(/MSIE/.test(navigator.userAgent))browser='poop';

saveTicket=function(othersubj){
	var f=document.ticket;
	if(!f || typeof(f) == 'undefined') { alert('Form not found! Using IE? Try Chrome!'); return; }

	var subj = f.Subject.value; // options[f.Subject.selectedIndex].value;
	var cust = f.CustomSubject.value;
	if((subj=='0' || subj==othersubj) && cust == '') {
		alert('Please choose/enter a subject.');
		return;
	}
	if(document.ticket.Message.value < 2) {
		alert('Please enter details for the ticket.');
		return;
	}
//	if(browser=='poop') {
//		var iframe=document.getElementById('frmtarget');
//		f.target=iframe;
//		setTimeout("lC('mainsite','support')", 1500);
//		return true;
//	} else {
		ajaxSubmit(document.ticket,'',"lC('mainsite','support')");
//	}
}
addResp=function(tick){
	var resptext = escape(document.getElementById('addresponse').value);
	var sroll = document.getElementById('NewStatus');
	var status = sroll.value;
	if(resptext=='') {
		var statustext=sroll.options[sroll.selectedIndex].text;
		if(statustext != document.getElementById('ticketstatus').innerHTML) { // if changed status, save with appropriate response.
			resptext = 'Status set to ' + statustext;
		}
	}
	var ctel=document.getElementById('CopyTo')
	var ct = '';
	if(typeof(ctel)!='undefined') ct = ctel.value;
	if(resptext && resptext != '') lC('mainsite','support?a=addresp&resptext='+resptext+'&tid='+tick+'&stid='+status+'&copyto='+ct);
}


var chBG=function(fn){
	document.body.style.background='url(/images/'+fn+') repeat';
}
// toggler for stars and moons in email
// changes displayed image and send xmlhttp
// request to server to do the deed.
var tglStar=function(mid){
	var el = document.getElementById('star'+mid);
	if(typeof(el)=='undefined') return false;
	var switchto=0;
	if(/graystar/.test(el.src)) switchto=1;
	var xmlhttp=getXMLObj();
	if(!xmlhttp)return;
	var url='/email.php?setstar='+mid+'&newval='+switchto;
	xmlhttp.open('get',url,true);
	xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){
		if(switchto==1) el.src='images/yellowstar.png';
		else el.src='images/graystar.png';
	}};
	xmlhttp.send(null);	
}
var tglMoon=function(mid){
	var el = document.getElementById('moon'+mid);
	if(typeof(el)=='undefined') return false;
	var switchto=0;
	if(/graymoon/.test(el.src)) switchto=1;
	var xmlhttp=getXMLObj();
	if(!xmlhttp)return;
	var url='/email.php?setmoon='+mid+'&newval='+switchto;
	xmlhttp.open('get',url,true);
	xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){
		if(switchto==1) el.src='images/yellowmoon.png';
		else el.src='images/graymoon.png';
	}};
	xmlhttp.send(null);	
}
// unused
/*
var popNames=function(sstr,rdid,typ,leaveopts){
	if((sstr && sstr.length>1)||typ=='chu'){
		if(!leaveopts)leaveopts=0;
		var xmlhttp=getXMLObj();
		if(!xmlhttp)return;
		var url='/uSearch.php?last='+sstr+'&type='+typ;
		xmlhttp.open('get',url,true);
		xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){
			var names=document.getElementById(rdid);
			names.options.length=leaveopts;
			var ret=xmlhttp.responseText;
			var tar=ret.split(';');
			var numrec=tar.length;
			for (var a=0;a<numrec;a++){
				var par=tar[a].split(':');
				if(par[1]){
					names.options.add(new Option(par[1],par[0]));
				}
			}
		}};
		xmlhttp.send(null);
	}
}
*/
// reads the fields/values on a form and submits it via ajax request, allowing arbitrary code execution in the current
// page without a page load when submitting the form. The best benefit of this is being able to check/validate form
// fields at the server without the browser posting the form (and thus traveling to) to a new URL.
var ajaxSubmit=function(f,url,cbcode,reqflds,HEname){ //,piid){
	if(typeof(HEname)=='undefined' || !HEname)HEname='';
	if(typeof(cbcode)=='undefined' || !cbcode) cbcode='';
	var x=getXMLObj();
	if(!x)return;
	var p='';
	var flen=f.elements.length;
	var re=null;
	if(reqflds) re = new RegExp(','+reqflds+',');
	if(HEname != '' && typeof(FCKeditorAPI) != 'undefined') {
		var oeditor = FCKeditorAPI.GetInstance(HEname)
		if(oeditor) f.elements[HEname].value = escape(oeditor.GetXHTML());
	}
	for(var a=0;a<flen;a++){
		if(reqflds){
			if(re.test(','+f.elements[a].name+',') && f.elements[a].value=='') {
				alert("Missing required field: "+f.elements[a].name);
				f.elements[a].focus();
				return;
			}
		}
		if(f.elements[a].name && ((f.elements[a].type!='radio'&&f.elements[a].type!='checkbox') || f.elements[a].checked)){
			if(p)p+='&';
				var fv=f.elements[a].value;
				if(/^select-multi/i.test(f.elements[a].type)) {
					var sopts = f.elements[a].options;
					fv='';
					for(var soptcnt=0; soptcnt<sopts.length; soptcnt++){
						if(sopts[soptcnt].selected) {
							if(fv) fv+=',';
							fv+=sopts[soptcnt].value;
						}
					}
				} else {
					fv = fv.replace(/&/g,'%26');
				}
				p+=f.elements[a].name+'='+fv;
		}
	}
	if(url=='')url=f.action;
	x.open('post',url,true);
	x.setRequestHeader('Content-Type','application/x-www-form-urlencoded' );
	x.onreadystatechange=function(){if(x.readyState=='4'){
		var t=x.responseText;
		if(/^[\s]*OK[\s]*$/.test(t) || /SUCCESS/.test(t)) {
			if(cbcode && cbcode != '') eval(cbcode);
		} else if(/^goto:/.test(t)){
			var tar=t.split(':');
			if(tar[1]){
				window.location.href=tar[1];
			}
		} else if (t != '' && t != 'OK') {
			alert(t);
			if(/success/i.test(t) && cbcode && cbcode != '') eval(cbcode);
		}
	}};
	x.send(p);
}
// not used that I can see....
/*
var chP=function(o,n1,n2) {
	if(!o)return;
	if(!n1&&!n2 || n1!=n2 || n1.lengh<4){ alert("New passwords do not match or too short."); return;}
	var xmlhttp=getXMLObj();
	if(!xmlhttp)return;
	xmlhttp.open('post','/portal.php',false);
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded' );
	var params='op='+escape(o)+'&np='+escape(n1);
	xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){
		if(/^ERROR/.test(xmlhttp.responseText)){alert(xmlhttp.responseText);}
		else {alert(xmlhttp.responseText); lC('contentSettings','/portal.php?a=edit');}
	}};
	xmlhttp.send(params);
//	alert(o+' '+n1+' '+n2);
}
*/
// nice idea, but broken....
function addConFromEm(mid) {
	var url='/contacts.php?a=addfromemail&id='+mid;
//	doPopup(url,600,500);
	popIn(url,600,550,'','Add Contact');

}	
// global compose email popup function
function cmpEm(argstr) {
	argstr = argstr.replace(/ & /, escape(" & "));
	doPopup('/composeEmail.php?s=Compose+Email&popout=1&'+argstr, 625, 450);
}
// for context menu functions such as reply, forward, replyall
function procEm(mid,action) {
	doPopup('/composeEmail.php?a='+action+'&ID='+mid,650,550)
}
// popout email from context menu
function popEm(mid){
	if (/,/.test(mid)){
		var tar = mid.split(',');
		var tarlen=tar.length;
		if(tarlen<=5) {
			for(var a=0; a<tarlen; a++){
				doPopup('email.php?a=view&ID='+tar[a]+'&popout=1',650,550)
			}
		} else doPopup('email.php?a=view&ID='+tar[0]+'&popout=1',650,550)
	} else doPopup('email.php?a=view&ID='+mid+'&popout=1',650,550)
}

var IMWindows = new Array();
// general popup function
function doPopup(url,w,h,l) {
	var nm = url.replace(/[^a-z0-9]+/g,'');
	var itop = screen.height/2-(h/2);
	var ileft = screen.width/2-(w/2);
	if(l)ileft=100;
	var isim=0;
	if(/^\/im\.php/.test(url)) isim=1;
	if(isim && typeof(IMWindows[nm]) != 'undefined' && !IMWindows[nm].closed) { IMWindows[nm].focus();
	} else {
		var pos = "top=" + itop + ",left=" + ileft/3;
		pos += ',location=1';
		var w=window.open(url,nm,pos+',height='+h+',width='+w+',scrollbars=yes,status=yes,resizable=yes');
		if(w) {
			if(isim) IMWindows[nm]=w;
			w.focus();
		}
	}
}
// open popup IM window to given recipient
var goIM=function(toaid,po){
	var url='/im.php?from='+toaid+'&a=view';
	var nm = url.replace(/[^a-z0-9]+/g,'');
	nm += 'po1'; // for poppedout version
	// if popped out already, just focus there.
	if(typeof(IMWindows[nm])!='undefined' && !IMWindows[nm].closed){ IMWindows[nm].focus(); return; }
	po=1;
	if(po==1) {
		doPopup(url+'&po=1',600,400,1);
	} else {
		var x=document.getElementById('impi'+toaid);
		if(!x||typeof(x)=='undefined') popIn(url,550,400,'impi'+toaid,'IM');
	}
}
// check new mail, IMs, contents of 'online' menu, support tickets.
// gets back a bunch of data from the server with funky separators
// to be split up and processed
var mailCheck=function(){
	var xmlhttp=getXMLObj();
	if(!xmlhttp)return;
	var url='/email.php?a=checknew2';
	xmlhttp.open('get',url,true);
	xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){
		var ret=xmlhttp.responseText;
		//if(/LOGGED OUT/.test(ret) || ret=='' || /name="login"/.test(ret)) {
		if(!/xxRxx/.test(ret)) {
			self.location.href='/login.php';
			return;
		}
		var age = '';
		if(ret!='0'){
			lC('emFDiv','email.php?gf=1');
			if(typeof(playSnd)!='undefined')playSnd('snd3wav');
			if(/xxRxx/.test(ret)){
				var tar=ret.split('xxRxx');
					age=tar.shift();
					var z=document.getElementById('lastEMAge');
					if(z && typeof(z)!='undefined'){
						z.innerHTML=age;
					}
					// update window title
					var tmpar=age.split(/\s/);
					var unread=parseInt(tmpar.shift());
					if(unread >= 1){
						var wtit = document.title;
						wtit = wtit.replace(/^\([\d]+\) /,'');
						document.title = '(' + unread + ') ' + wtit;
					} else {
						document.title = document.title.replace(/^\([\d]+\) /,'');
					}
				var ollist = '';
				var imlist = '';
				for(var a=0;a<tar.length;a++){
					if(!/xFx/.test(tar[a])) continue;
					var tar2=tar[a].split('xFx');
					if (tar2[0] == 'ol') { // online list entry - "ol",aid,name,email
						var olcls='offline';
						if(tar2[4].substring(0,3)=='On ') {
							var thiscls='online';
							var titparts = tar2[4].split(', Idle for '); // get "xx minutes/hours/days" into titparts[1]...
							var idleparts = titparts[1].split(' '); // idleparts[0] is numeric portion, [1] is units.
							if(/hour|day/.test(idleparts[1]) || (/minute/.test(idleparts[1]) && parseInt(idleparts[0])>=10)) {
								thiscls='idle';
							}
							olcls=thiscls+'" title="'+tar2[4];
						
						} else olcls = 'offline" title="Offline for '+tar2[4];
						ollist += '<div style="white-space:nowrap;"><a style="display:inline !important" href="javascript:cmpEm(\'to='+tar2[3]+
						'\')"><img src="/images/mail.png" border="0" align="absmiddle" /></a> <a class="'+olcls+'" href="javascript:goIM('+
						tar2[1] + ')" style="display:inline !important">'+tar2[2]+'</a></div>';
					} else if(tar2[0] == 'IM') { // AIDs of new IM senders
						imlist = tar2[1];
						var imar = imlist.split(',');
						for (var j=0; j<imar.length; j++){ if(imar[j]>0) goIM(imar[j]); }
					} else if(tar2[0] == 'tickets'){
						var sl=document.getElementById('SupportLink');
						if(typeof(sl) != 'undefined'){
							if(tar2[1] > '0') {
								sl.style.fontWeight='bold';
								sl.innerHTML='Support ('+tar2[1]+')';
							} else {
								sl.style.fontWeight='normal';
								sl.innerHTML='Support';
							}
						}
					} else { // must be an email row
						addEmRow(tar2[0],tar2[1],tar2[2],tar2[3]);
					}
				}
				var ol=document.getElementById('ol_list');
				if(ol!=null&&typeof(ol)!='undefined')ol.innerHTML=ollist;
				shadeSndrs();
			}
		}
	}};
	xmlhttp.send(null);
}
// add and remove class functions... add or remove a string from an elements 'className' property.
var addClass=function(cur,add){
	var re=new RegExp(add);
	if(!cur || cur=='undefined') cur='';
	if(!re.test(cur))cur+=' '+add;
	return cur;
}
var removeClass=function(cur,rem){
	var re=new RegExp(rem,'g');
	cur=cur.replace(re,'');
	return cur;
}
var current_open_email=0;
var current_email_first=0;
var emails_per_page=20;
var mmh=null;
var shrink_top_to = 1;//250;
// show an email message in mailShow div, hiding mailMain div
var emShowMail=function(mid){
	var ms = document.getElementById('mailShow');
	var mm = document.getElementById('mailMain');
	if(typeof(mm)=='undefined' || !mm) return; //mm = document.getElementById('mailMain1');
	if(browser=='poop') mm.style.marginRight='15px';
	if(!ms||!mm)return;
	var url='/email.php?ID='+mid+'&a=view';
	var md = document.getElementById('msgdiv'+mid); // get message div element
	if( md && md.style.display!='none') { emBack(); }
	else {
		current_open_email=mid;
		if(browser=='poop')ms.innerHTML='';
		if(mm.offsetHeight>shrink_top_to&&browser=='poop'){mmh=mm.offsetHeight;}
	mm.style.display='none';
		ms.style.display='block';
		ms.style.top='0px';
		var emtr = document.getElementById('emTR'+mid);
		clearEmRC('opn');
		emtr.className=removeClass(emtr.className,'emNew');
		emtr.className=addClass(emtr.className,'opn');
		emtr.scrollIntoView(false);
		if (ms.childNodes.length) { // hide all msg divs
			var l=ms.childNodes.length;
			for (var a=0; a<l; a++)	if(/^msgdiv/.test(ms.childNodes[a].id))ms.childNodes[a].style.display='none';
		}
		if(!md||typeof(md)=='undefined') { // if it didn't exist, create it and load its content
			md=document.createElement('div');
			var did='msgdiv'+mid;
			md.id=did;
			md.style.position='relative';
			ms.appendChild(md);
			lC(md,url);
		} else { // else if it did exist, just display it
			md.style.display='block';
		}
	}
}
// back from email message view to index
var emBack=function(){
	current_open_email=0;
	var ms = document.getElementById('mailShow');
	var mm = document.getElementById('mailMain');
	if(typeof(mm)=='undefined' || !mm) mm = document.getElementById('mailMain1');
	if(browser=='poop') mm.style.marginRight='0px';
	if(!ms||!mm)return;
	mm.style.display='block';
	var mid=0;
	if (browser=='poop')ms.innerHTML='';
	else if (ms.childNodes.length) { // hide all msg divs
		var l=ms.childNodes.length;
		for (var a=0; a<l; a++)
			if(ms.childNodes[a].style.display!='none')ms.childNodes[a].style.display='none';
	}
	clearEmRC('opn');
	ms.style.display='none';
}
var jsmodlist;
var right=function(e){if(e.which>1)return false};

// remove a class from each row in emTbl, and hide context menu
// this happens after you actually do an action on a context menu
var clearEmRC=function(cls){
	var tbl=document.getElementById('emTbl');
	var trs=tbl.getElementsByTagName('tr');
	var num=trs.length;
	for(var a=0;a<num;a++){
		trs[a].className=removeClass(trs[a].className,cls);
	}
	document.getElementById('EmFMenu').style.display='none';
}
// show email context menu - folder list submenu for moving an email
var showEmFMenu=function(e){
	var tg;
	if(browser=='poop'){var e=window.event;tg=e.toElement;}
	else{tg=e.target;}
	var mf=document.getElementById('EmFMenu');
	mf.style.display='block';
	tg.onmouseout=function(e){
		var tg;
		var mf=document.getElementById('EmFMenu');
		if(!e){var e=window.event;tg=e.toElement;}
		else tg=e.relatedTarget;
		if(tg&&tg!=mf&&tg.parentNode.id!=mf.id&&tg!=this){mf.style.display='none';}
	}
}
// main email context menu
var showEmCMenu=function(e,mid){
	if(!e)var e=window.event;
	var x=e.clientX+2;
	var y=e.clientY+2;
	var m = document.getElementById('EmCMenu');	// main right-click menu
	var mf=document.getElementById('EmFMenu'); // extra folder menu that pops out when mousing over "Move to Folder"
	mf.innerHTML='';
	// load EmFMenu with folders from tofld rolldown - made into appropriate links on the fly
	var fl=document.getElementById('tofld').options;
	for (var a=1;a<fl.length;a++){
		var lnk=document.createElement('a');
		lnk.href="javascript:mvEm('"+mid+"',"+fl[a].value+")";
		var txt = fl[a].text;
		lnk.className='pmlink';
		if(txt.indexOf('/')>=0) {
			lnk.style.paddingLeft='10px';
		}
		lnk.appendChild(document.createTextNode(txt));
		mf.appendChild(lnk);
	}
	m.style.display='block';
	// some baloney to close the menus if you mouse out of them or when you click on them
	m.onmouseout=function(e){
		var tg;
		if(!e) { var e=window.event; tg=e.toElement; }
		else { tg=e.relatedTarget; }
		var fm=document.getElementById('EmFMenu');
		if(tg&&tg!=this&&tg.parentNode!=this&&tg!=fm&&tg.parentNode!=fm){clearEmRC('cur');this.style.display='none';}
	};
	mf.onmouseout=function(e){
		var tg;
		if(!e){var e=window.event;tg=e.toElement;}
		else tg=e.relatedTarget;
		if(tg&&tg!=this&&tg.parentNode!=this)this.style.display='none';
	}
	m.onclick=function(){clearEmRC('cur');this.style.display='none';}
	// place it accordingly
	var lower=0;
	if(browser!='poop'&&x>window.innerWidth-m.offsetWidth-20)x-=m.offsetWidth;
	else if (browser=='poop'&&x>document.body.clientWidth-m.offsetWidth-20)x-=m.offsetWidth;
	if(browser!='poop'&&y>window.innerHeight-m.offsetHeight-10){ y-=m.offsetHeight; lower=1; }
	else if(browser=='poop'&&y>document.body.clientHeight-m.offsetHeight-10) { y-=m.offsetHeight; lower=1; }
	m.style.top=y+'px';
	m.style.left=x+'px';
	if(fl.length<10 || (fl.length>=10 && lower==0)) { mf.style.top='45px'; mf.style.bottom=''; }
	else { mf.style.bottom = '10px'; mf.style.top=''; }
	mf.style.left=(m.offsetWidth-8)+'px';
	m.style.zIndex='2002';
	mf.style.zIndex='2005';
	m.innerHTML=m.innerHTML.replace(/\'[0-9,]+\'/g,"'"+mid+"'");
	clearEmRC('cur'); // clear 'cur' class from all emTbl rows
	// add 'cur' class to right-clicked item (or now, items if it's a multiple selection
	if (mid.indexOf(',')>-1){
		var tar=mid.split(',');
		var tarlen=tar.length;
		for(var a=0;a<tarlen;a++){
			var tr=document.getElementById('emTR'+tar[a]);
			if(tr)tr.className=addClass(tr.className,'cur');
		}
	} else {
		var tr=document.getElementById('emTR'+mid);
		if(tr)tr.className=addClass(tr.className,'cur');
	}
	// close the menus if there is a click elsewhere too
	if(browser!='poop'){
		window.onclick=function(e){
			if(e.which==1){clearEmRC('cur');document.getElementById('EmCMenu').style.display='none';window.onclick=function(){};}
		};
	}else{
		document.body.onmouseup=function(e){
			e=window.event;
			if(e.button==1){clearEmRC('cur');document.getElementById('EmCMenu').style.display='none';document.body.onmouseup=function(){};}
		};
	}
}
// add a new (first) email row to the message list
var addEmRow=function(mid,sndr,subj,mdate){
	var tbd=document.getElementById('emTbd'); if(!tbd)return;
	var trid='emTR'+mid;
	if(document.getElementById(trid)) return;
	var tr=document.createElement('tr');
	tr.id=trid;
	tr = tbd.insertBefore(tr,tbd.firstChild);
	tr.className='emNewAuto';
	var td=document.createElement('td');
	td = tr.appendChild(td);
	var a=document.createElement('a');
	a = td.appendChild(a);
	a.href='javascript:mvEm('+mid+',4)';
	a.innerHTML='<img src="/images/cross.png" align="absmiddle" border="0" />';
	td = document.createElement('td');
	td=tr.appendChild(td);
	td = document.createElement('td');
	td=tr.appendChild(td);
	td = document.createElement('td');
	td=tr.appendChild(td);

	var stara = document.createElement('a');
	stara = td.appendChild(stara)
	stara.href='javascript:tglStar('+mid+')';
	stara.className='star';
	var starimg = document.createElement('img');
	starimg.border='0';
	starimg = stara.appendChild(starimg);
	starimg.src = '/images/graystar.png';
	starimg.id = 'star'+mid;
	var cb=document.createElement('input');
	cb.type='CHECKBOX';
	cb=td.appendChild(cb);
	cb.id='cb'+mid;
	cb.value=mid;
	cb.onclick=function(e){if(!e)e=window.event;if(!e)return;chkE(e,this.parentNode.parentNode,this.checked,'cb');};
	td = document.createElement('td');
	td=tr.appendChild(td);
	td.onclick=function(){emShowMail(mid);};
	var div=document.createElement('div');
	div=td.appendChild(div);
	div.id='sndr'+mid;
	div.className='emsndr';
	td.style.paddingRight='7px';
//	new Draggable('sndr'+mid,{revert:true,ghosting:false});
	div.appendChild(document.createTextNode(sndr));
	td=document.createElement('td');
	td=tr.appendChild(td);
	div=document.createElement('div');
	div=td.appendChild(div);
	div.onclick=function(){emShowMail(mid);};
	div.id='sb'+mid;
	div.appendChild(document.createTextNode(subj));
	td=document.createElement('td');
	td=tr.appendChild(td);
	td.appendChild(document.createTextNode(mdate));
}

var shadeSndrs=function(){
	var wd=0;
	var tbl=document.getElementById('emTbl');
	if(tbl==null)return;
//	if(browser=='poop') tbl.parentNode.style.marginRight='15px';
	var divs=tbl.getElementsByTagName('div');
	var n=divs.length;
	if(!n)return;
	var op=0;
	for (var a=0; a<n; a++) {
		if (/^sndr|^sb/.test(divs[a].id)) {
			var el = divs[a];
			if (/^sndr/.test(el.id)) {
				// uncomment following to have tooltips on email senders showing email address.
				//el.title = el.innerHTML.replace(/&[lg]t;/g,'  ');
				el.parentNode.parentNode.oncontextmenu=
				function(e){
					var mid=this.id.replace('emTR','');
					if(!e)e=window.event;
					var cb = document.getElementById('cb'+mid);
					// if clicked row is 'checked', then select it and all other checked rows
					// i.e. change the 'mid' variable into a comma separated list of checked mids to pass to showEmCMenu()
					if(cb&&cb.checked==true){
						var xmid='';
						var tbl=document.getElementById('emTbl');
						var trs=tbl.getElementsByTagName('tr');
						var trslen=trs.length;
						for(var z=0;z<trslen;z++){
							if(/^emTR/.test(trs[z].id)){
								var zmid =trs[z].id.replace('emTR','');
								if(document.getElementById('cb'+zmid).checked) {
									if(xmid)xmid += ',';
									xmid+=zmid;
								}
							}
						}
						if(xmid!='')mid=xmid; // replace 'mid' with multiple comma-separated mid string
					}
					showEmCMenu(e,mid);
					return false;
				}
			}
		}
	}
}
var lastchindex=-1;
// check all boxes in a list, with highlighting
var chkEAll=function(cbxbox,chkd){
	var tbl=document.getElementById(cbxbox);
	var cbx=tbl.getElementsByTagName('input');
	var num=cbx.length;
//	document.getElementById('emchkall').checked = chkd;
	for (var a=0;a<num;a++){
		if(cbx[a].type=='checkbox'){
			cbx[a].checked=chkd;
			var par=cbx[a].parentNode.parentNode; // row
			if(chkd)
				par.className=addClass(par.className,'sel');
			else
				par.className=removeClass(par.className,'sel');
		}
	}
}
// shift click fills in rows between current and last click...
var chkE=function(e,tr,chkd,cbxprefix){
	// e is event, tr is table row - must have an ID whose numeric is added to cbxprefix to give the ID of the row's checkbox.
	var par=tr.parentNode;
	var mid=tr.id.replace(/[^0-9]+/g,'');
	if(!e)document.getElementById(cbxprefix+mid).checked=chkd;
	if(e&&e.shiftKey) {
		if (lastchindex>=0&&lastchindex<tr.rowIndex) {
			for(var a=lastchindex;a<tr.rowIndex;a++)
				chkE(0,par.childNodes[a],chkd,cbxprefix);
		} else if(lastchindex>=0) {
			for(var a=tr.rowIndex+1;a<=lastchindex;a++)
				chkE(0,par.childNodes[a],chkd,cbxprefix);
		}
	}
	if(chkd)
		tr.className=addClass(tr.className,'sel');
	else
		tr.className=removeClass(tr.className,'sel');
	if(e)lastchindex=tr.rowIndex;
}
//show/hide to-folder list -- not used now
var setToFld=function(s){
	var nx = document.getElementById('tofld');
	if(s.value=='move')nx.style.display='';else nx.style.display='none';
};
// central function to do various email actions from the form items at the top of email lists
var doE=function(){
	var atype,act,fld;
	atype=document.getElementById('xst').value; // 1=selected, 2=all, 3= > 1 month old, 4= >3 months, 5= >6months, 6= >1 year
	act=document.getElementById('xs').value;
	fld=document.getElementById('tofld').value
	var mids='';
	switch(atype){
		case '1':
			var tr=document.getElementById('emTbl');
			var inputs = tr.getElementsByTagName('input');
			for(var a=0; a<inputs.length; a++){
				if(inputs[a].type=='checkbox' && inputs[a].checked) {
					if(mids)mids += ',';
					mids+=inputs[a].id.replace(/^cb/,'');
					inputs[a].checked=false;
				}
			}
			break;
		case '2':
			mids='all';
			break;
		case '3': mids='byage:1'; break;
		case '4': mids='byage:3'; break;
		case '5': mids='byage:6'; break;
		case '6': mids='byage:12'; break;
	}
	if(mids.length){
		switch(act){
			case 'archive':
				mvEm(mids,3); break;
			case 'del':
				mvEm(mids,0); break;
			case 'movetrash':
				mvEm(mids,4); break;
			case 'move':
				if(fld) mvEm(mids, fld); break;
			case 'markread':
				setEm(mids,act); break;
			case 'markunread':
				setEm(mids,act); break;
		}
	} else alert ('woops');
};
// move emails, sometimes into other universes
function mvEm(mid, fid, wclose) {
	var xmlhttp=getXMLObj();
	if(!xmlhttp)return;
	if (fid==0) { // delete
		var ok=confirm("Permanent Delete: Are you sure?");
		if(!ok)return;
	}
	var url='/email.php?a=move&ID='+mid+'&fid='+fid;
	mid+='';
	if(mid!='all'&&mid.indexOf('byage')==-1) {
		var g=mid.split(',');
		for (var a=0; a<g.length; a++) {
			var x = document.getElementById('emTR'+g[a]);
			if(!x&&opener) x=opener.document.getElementById('emTR'+g[a]);
			if (x) {
				x.parentNode.removeChild(x);
			}
		}
	}
	if(mid==parseInt(mid)){
		if(document.getElementById('msgdiv'+mid)){
			emBack();
		}	
	}
	xmlhttp.open('get',url,true);
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4) {
			if(mid=='all'||mid.indexOf('byage')!=-1) { lC('mainsite','/email.php'); }
			else if(wclose==1) { opener.focus(); self.close(); }
			else if (wclose==2) { emBack(); }
			lC('emFDiv','/email.php?gf=1');
			chkEAll(false);
		}
	}
	xmlhttp.send(null);
}
// set emails, to read or unread
function setEm(mid, act) {
	var xmlhttp=getXMLObj();
	if(!xmlhttp)return;
	var cls;
	var url='/email.php?a='+act+'&ID='+mid;
	if(mid!='all'&&mid.indexOf('byage')==-1){
		var g=mid.split(',');
		for (var a=0; a<g.length; a++) {
			var x = document.getElementById('emTR'+g[a]);
			if(!x) x=opener.document.getElementById('emTR'+g[a]);
			if (x) {
				if (act=='markread'){x.className=removeClass(x.className,'emNew');}
				else if(act=='markunread'){x.className=addClass(x.className,'emNew');}
				document.getElementById('cb'+g[a]).checked=false;
			}
		}	
	}
	xmlhttp.open('get',url,true);
	if(mid=='all'||mid.indexOf('byage')==0){xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4){
			lC('mainsite','/email.php');
		}
	};} else {
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
				lC('emFDiv','/email.php?gf=1');
				chkEAll(false);
			}
		}
	}
	xmlhttp.send(null);
}
// kinda steered away from this.. might be used a bit in email
popIn=function(url,w,h,piid,title){
	if(typeof(piid)=='undefined' || !piid) piid='pi';
	if(typeof(title)=='undefined' || !title) title='GIM';
	hidePI(piid);
	if(!w)w=70;
	if(!h)h=100;
	var t,l;
	var ww,wh;
	if(/MSIE/.test(navigator.userAgent)) { wh=document.body.clientHeight; ww=document.body.clientWidth; }
	else { wh=window.innerHeight; ww=window.innerWidth; }
	if(w>ww) { w=ww-10; }
	if(h>wh) { h=wh-10; }
	l=(ww-w)/2;
	t=(wh-h)/2;
	var div=document.createElement('div');
	document.body.appendChild(div);
	div.style.position='absolute';
	div.style.left=l+'px';
	div.style.top=t+'px';
	div.style.width=w+'px';
	div.style.height=(h+2)+'px';

	div.style.zIndex = '10000';
	div.className='popIn';
	div.style.overflow='auto';
	div.id=piid;
	var hdiv=document.createElement('div');
	hdiv.id = piid + '_pihdr';
	div.appendChild(hdiv);
	hdiv.className='PIHeading';
	hdiv.style.position='relative';
	hdiv.style.textAlign='right';
	var exst=''
	if(browser=='poop') exst='color:black;';
	hdiv.innerHTML='<div style="float:left;">'+title+'</div>'+
	'<a href="javascript:togglePI(\''+piid+'\')"><img src="/images/updown.gif" border="0" /></a>'+
	' <a href="javascript:hidePI(\''+piid+'\')"><img src="/images/x.gif" border="0" /></a>';
	var bdiv=document.createElement('div');
	div.appendChild(bdiv);
	bdiv.id=piid+'_pibody';
//	bdiv.style.position='relative';
	new Draggable(piid+'',{revert: false, handle: 'PIHeading'});
	div.scrollIntoView(false);
	lC(piid+'_pibody',url);
}
// hide a popIn()...
hidePI=function(piid){
	if(piid=='undefined' || !piid) piid='pi';
//	var b=document.body;
	if(/^impi/.test(piid)){
		var fid=piid.replace('impi','')-0;
		if(imintervals[fid]) clearInterval(imintervals[fid]);
	}
	var pi=document.getElementById(piid);
	if(pi) {
		pi.parentNode.removeChild(pi);
		//pi.innerHTML='';
		//pi.style.display='none';
	}
}
var piheight=0;
togglePI=function(piid){
	if(piid=='undefined' || !piid) piid='pi';
	var pi=document.getElementById(piid);
	var pih=pi.style.height;
	var pihdr=document.getElementById(piid+'_pihdr');
	var pibody=document.getElementById(piid+'_pibody');
	if(typeof(pibody) != 'undefined'){
		if(pibody.style.display=='none' && typeof(pi.oriheight)!='undefined') {
			pi.style.height=pi.oriheight;
			Element.show(pibody);
			pi.scrollIntoView(false);
		} else {
			pi.oriheight = pi.style.height;
			Element.hide(pibody);
			pi.style.height='20px';
		}
	}
}
// image unblock in email display
emIUB=function(mid){
	var emb = document.getElementById('embody'+mid);
	var content=emb.innerHTML;
	content = content.replace(/<!--IMG/,'<img');
	content = content.replace(/ IMG-->/,'>');
	emb.innerHTML=content;
	document.getElementById('imgwarn'+mid).style.display='none';
}

var oeditor=null;
// IM initter
var initter=function(fid,fromname){
	setIMHeight(fid); var intvl=7000;if(fid==0)intvl=90000;
	if(document.getElementById('im_msg'+fid))document.getElementById('im_msg'+fid).focus();
	var impi=	document.getElementById('impi'+fid);
	var chatter=document.getElementById('chatter'+fid);
	if(chatter) chatter.scrollTop = chatter.scrollHeight;// + control.offsetHeight + 10;
	var fix = fid - 0;
	if(imintervals[fix]) clearInterval(imintervals[fix]);
	imintervals[fix]=setInterval('checkNewIM('+fid+')',intvl);
	if(playSnd && (playSnd & 1)) Sound.play('/sounds/newmessage.wav');

}
// something with IMs... =)
var setSBE=function(aid,onoff){
	var x=document.getElementById('im'+aid);
	if(!x||typeof(x)=='undefined') x=opener.document.getElementById('im'+aid);
	if(!x||typeof(x)=='undefined') x=opener.top.document.getElementById('im'+aid);
	if(x){
		if(onoff==1){ //x.style.backgroundColor='yellow';x.style.border='1px solid black'; }
			x.className = addClass(x.className,'msgwait');
		}else { // x.style.backgroundColor=''; x.style.border=''; }
			x.className = removeClass(x.className,'msgwait');
		}
	}
}

var checkNewIM=function(fromid){
	var xmlhttp=getXMLObj();
	if(!xmlhttp)return;
	var url='/im.php?a=cn&from='+fromid;
	xmlhttp.open('get',url,true);
	var imtdiv=document.getElementById('imtdiv');
	if(imtdiv) imtdiv.innerHTML='*';
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4){
			if(imtdiv) imtdiv.innerHTML='';
			if(xmlhttp.responseText!=' '){
				var mar = xmlhttp.responseText.split('--endmsg--');
//				if(typeof(playSnd)!='undefined') playSnd('snd2wav');
//				else if (opener && typeof(opener.playSnd)!='undefined') opener.playSnd('snd2wav');
//				Sound.play('/sounds/beep.ogg'); //newmessage.wav');
				if(mar.length>0){
					var ml=mar.length;
					var cnt=0;
					for(var a=0;a<ml;a++){
						var ar=mar[a].split('--xx--');
						var from=ar[0];
						var msg = ar[1];
						if(from&&msg){
							addRow(from,msg,1,fromid);
							++cnt;
						}
					}
					if(playSnd && (playSnd & 2)) Sound.play('/sounds/newmessage.wav');
				}
			}
		}
	}
	xmlhttp.send(null);
}
var addTxtNode=function(obj,txt){
	if(obj){
		var x = document.createTextNode(txt);
		obj.appendChild(x);
	}
}
// send IM
var sendMsg=function(toid,myAID){
	var msg='';
		var omsg = document.getElementById('im_msg'+toid);
		msg=omsg.value;
		omsg.value='';
	var xmlhttp = getXMLObj();
	if(!xmlhttp)return;// false;
	var oto = document.getElementById('to'+toid);
	if(!toid) toid=oto.value;
	setSBE(toid,0);
	if(!toid || !msg) return;// false;
	var url = '/im.php';
	var params='a=send&to='+toid+'&msg='+encodeURIComponent(msg);
	xmlhttp.open('POST',url,true);
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded' );
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4){
			if(toid!=myAID) addRow('Me (' + xmlhttp.responseText+')',msg,1,toid);
			else checkNewIM(toid);
		}
	}
	xmlhttp.send(params);
}
// add IM row
var addRow=function(from,msg,isnew,toid){
	var chatter=document.getElementById('chatter'+toid);
	var control=document.getElementById('control'+toid);
	var div=document.createElement('div');
	chatter.appendChild(div);
	div.style.textAlign='left';
	if (!isnew) div.className = addClass(div.className,'old');

	var tbl = document.createElement('table');
	var tbd = document.createElement('tbody');
	div.appendChild(tbl);
	tbl.appendChild(tbd);
	var tr=document.createElement('tr');
	tbd.appendChild(tr);
	tr.vAlign='top';
	var td=document.createElement('td');
	tr.appendChild(td);
	td.width='150';
	var spn=document.createElement('span');
	td.appendChild(spn);
	if(from.substring(0,4)=='Me (')spn.className='';
	else {
		spn.className='them';
		if(isnew)setSBE(toid,1);
	}
	from = '<b>'+from;
	from = from.replace(' (','</b><br />(');
	spn.innerHTML=from; // + msg;
	var td2=document.createElement('td');
	tr.appendChild(td2);
	td2.className=spn.className;
	td2.innerHTML=msg;
	chatter.scrollTop = chatter.scrollHeight;// + control.offsetHeight + 10;
}
var setIMHeight=function(toid){
	if(document.getElementById('topMain')) return;
	var ch=document.getElementById('chatter'+toid);
	var co=document.getElementById('control'+toid);
	var wh;
	if(window.innerHeight)wh=window.innerHeight;
	else if(document.documentElement.clientHeight) wh=document.documentElement.clientHeight;
	else if(document.body.offsetHeight)wh=document.body.offsetHeight;
	else if(document.body.clientHeight)wh=document.body.clientHeight;
	if(co&&wh){
		var ht=wh - co.offsetHeight - 3;
		if(/MSIE/.test(navigator.userAgent)) ht -= 20;
		ht = ht + 'px';
		ch.style.height=ht;
		ch.scrollTop = ch.scrollHeight;
	}
}
var nsec='';
var nssec='';
var isIE=/MSIE/.test(navigator.userAgent);
// show a menu panel
enableSection=function(){
	var e = document.getElementById(nsec);
	var menu=document.getElementById('themenu');
	if(typeof(menu)=='undefined' || menu==null) return;
	var sec;
	sec = menu.getElementsByTagName('div');
	for(var a=0; a<sec.length; a++){
		var sid=sec[a].id;
		if(sid.substring(0,7)=='section'){
			sec[a].style.display='none';
			var ptit=sec[a].previousSibling;
			var tit = ptit.firstChild;
			if(typeof(tit)=='undefined')
				tit = ptit;
			if(tit.className == 'menutopHI') tit.className='menutop';
		}
	}
	var mainsite = document.getElementById('mainsite');
//	boy, does IE suck.
	ss = mainsite.getElementsByTagName('select');
//	boy, does IE suck.
	if(isIE) for(var a=0; a<ss.length; a++) ss[a].style.visibility='visible'; //display='';
	if(nsec=='')return;
	if(e){
		var ptit = e.previousSibling;
		var tit = ptit.firstChild;
		if(typeof(tit)=='undefined')
			tit = ptit;
		tit.className='menutopHI';
		var l = ptit.offsetLeft;
		e.style.display='block';
//	boy, does IE suck.
		if(isIE) l-=6;
		e.style.left=l + 'px';
		e.style.zIndex='500';
//	boy, does IE suck.
		if(isIE) for(var a=0; a<ss.length; a++) ss[a].style.visibility='hidden';//display='none';
	}
}
enableSubSection=function(){
	var e = document.getElementById(nssec);
	var menu=document.getElementById('themenu');
	if(menu==null) return;
	var sec = menu.getElementsByTagName('div');
	for(var a=0; a<sec.length; a++){
		var sid=sec[a].id;
		if(sid.substring(0,10)=='subsection'){
			sec[a].style.display='none';
			var ptit=sec[a].previousSibling;
			var tit = ptit.firstChild;
			if(typeof(tit)=='undefined')
				tit = ptit;
			if(tit.className == 'menutopHI') tit.className='menutop';
		}
	}

	var mainsite = document.getElementById('mainsite');
//	boy, does IE suck.
	ss = mainsite.getElementsByTagName('select');
//	boy, does IE suck.
	if(isIE) for(var a=0; a<ss.length; a++) ss[a].style.visibility='visible'; //display='';
	if(nssec=='')return;
	if(e){
		var ptit = e.previousSibling;
		var l = ptit.offsetLeft+150;
		e.style.display='block';
//	boy, does IE suck.
		if(isIE) l-=6;
		e.style.top = (ptit.offsetTop-8)+'px';
		e.style.left=l + 'px';
		e.style.zIndex='500';
//	boy, does IE suck.
		if(isIE) for(var a=0; a<ss.length; a++) ss[a].style.visibility='hidden';//display='none';
	}
}
var ttvis='0';

/*
var goFB=function(whosefb,frm,fld){
	var x=getXMLObj();
	x.open('get','/index.php?setglobalfiles='+whosefb,true);
	x.onreadystatechange=function(){if(x.readyState==4){
		mcFileManager.open(frm,fld,'','',{relative_urls : true});
		//alert('oh, hai!' + frm + ', '+fld);
	}}
	x.send(null);
}
*/
// our xmlhttp object getter for all ajax functions
function getXMLObj() {
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	  xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

// functions to do various things with leads
function goRoleChange(act,role){
	lid=getCheckedLeads();
	if(lid=='') return;
	var roleid=document.getElementById('arroleid').value;
	if(roleid<'1') return;
	
	if(confirm('Are you sure you want to change roles?'))
		lC('mainsite','leads.php?a='+act+'&id='+lid+'&rid='+roleid+'&role='+role);
	
}
function goDelLead(lid,role){
	if(lid == '-1'){
		lid=getCheckedLeads();
		if(lid=='') return;
	}
	if(confirm('Are you sure you want to delete this/these?'))
		lC('mainsite','leads.php?a=del&id='+lid+'&role='+role);
}
function broadcastCustom(roleid,curlistid){
	var lid=getCheckedLeads();
	if(!lid || lid=='') return;
	if(lid=='ALL') lid=curlistid;
	else if(!/,/.test(lid)) lid += ',' + lid;
	doPopup('broadcast.php?a=1&role='+roleid+'&ListID='+lid,700,640);
}		
function getCheckedLeads(){
	if(document.getElementById('AllRecs') && document.getElementById('AllRecs').checked) return 'ALL';
	var ms=document.getElementById('mainsite');
	var cbs = ms.getElementsByTagName('input');
	var l=cbs.length;
	var idstr='';
	for(var a=0;a<l;a++){
		if(cbs[a].type=='checkbox' && cbs[a].checked){
			if(cbs[a].id.substring(0,3)=='lcb'){
				var tid=cbs[a].id.substring(3);
				//alert(tid);
				if(idstr)idstr+=',';
				idstr+=tid;
			}
		}
	}
	return idstr;
}
// custom tooltip shower
function showTT(elid, url, pos) {
	var numid = elid.replace(/[^0-9]+/,'');
	if(ttvis != numid) return;
	if(!pos || typeof(pos)=='undefined') pos='left';
	var x=document.getElementById(elid);
	if(!x)return;
	x.style.cursor='wait';
	var xml=getXMLObj();
	xml.open('get',url,true);
	xml.onreadystatechange=function(){ if(xml.readyState==4){
		var t=document.getElementById('tt');
		if(!t || t==null || typeof(t)=='undefined') {
			t=document.createElement('div');
			t=document.body.appendChild(t);
			t.className='TT';
			t.id='tt';
		}
		if(t){
			t.style.width='';
			t.style.minWidth='220px';
			var left=TT_findPosX(x);
			var top =TT_findPosY(x);
			t.innerHTML=xml.responseText;
			if(pos=='left')t.style.left=(left - 10 - t.offsetWidth)+'px';
			else if(pos=='right') t.style.left=(left+10+x.offsetWidth)+'px';
			else if(pos=='center') t.style.left = (left - (t.offsetWidth/2)) + 'px';
			t.style.top=top+'px';
			t.style.visibility='visible';
			t.onmouseout=function(e){
				var tn=e.relatedTarget.tagName.toLowerCase();
				var tid=e.relatedTarget.id;
				if(tn != 'img' && tid != 'tt') hideTT();};
			}
		x.style.cursor='default';
	}};
	xml.send(null);
};
function hideTT(){ ttvis='0'; var tt = document.getElementById('tt'); if(tt && typeof(tt) !='undefined') tt.style.visibility='hidden'; };



// to execute javascripts loaded with lC
var evalRT=function(txt) {
	var s=txt.split(/<\/s.ript>/);
	if (s.length) {
		for (var a=0;a<s.length;a++){
			var tar=s[a].split(/<s.ript[^>]*>/);
			if (tar[1]) eval(tar[1]); //try { eval(tar[1]); } catch (e) { alert(tar[1])}
		}
	}
}

// our main ajax content loader... Many many things are loaded via this.
var lC=function(intoid, url, closeonfinish,execonfinish) {
	// kill opened menu upon click..
	if(intoid=='mainsite') { nsec=''; enableSection(); }
	var x;
	hideTT();
	if(typeof(intoid)=='string')x=document.getElementById(intoid);
	else { x=intoid; intoid=intoid.id; }
	if(!x)return;
	x.myurl=url;
	var xmlhttp=getXMLObj();if(!xmlhttp)return;
	//x.style.opacity=.65;
	xmlhttp.open('get',url,true);
	xmlhttp.onreadystatechange=function(){ if(xmlhttp.readyState==4){
		var ret=xmlhttp.responseText;
		if(ret.length>1){
			x.innerHTML='';
			x.innerHTML=ret;
			if(intoid == 'emFDiv') { // hack to copy email folder info to menu upon folder list refreshes
				var ofd=document.getElementById('myfdiv');
				if(ofd!=null && ofd && typeof(ofd)!='undefined') {
					var xret = ret.replace(/curF/,'');
					xret = xret.replace(/id=\"[^\"]+\"/,'');
				//	alert(xret);
					ofd.innerHTML=xret;
				}
			} else if(intoid=='mainsite') {
				if(typeof(document.body.scrollTo) != 'undefined') document.body.scrollTo(0,0);
			}
			if(ret && ret!='') evalRT(ret);
		}
		ret='';
		x.style.opacity=1;
		if(execonfinish&&execonfinish.length>1) eval(execonfinish);
		if(closeonfinish&&closeonfinish!=0) { closeonfinish.focus(); closeonfinish.close(); }
	}
	};
	xmlhttp.send(null);
}

// some insert-at-cursor function I found someplace to add stuff at the current cursor position (i.e. merge tags)
// thought it was harder, but turns out much simpler to do with the html editor
function insertAtCaret(areaId,text) { var txtarea = document.getElementById(areaId); var scrollPos = txtarea.scrollTop; var strPos = 0; var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? "ff" : (document.selection ? "ie" : false ) ); if (br == "ie") { txtarea.focus(); var range = document.selection.createRange(); range.moveStart ('character', -txtarea.value.length); strPos = range.text.length; } else if (br == "ff") strPos = txtarea.selectionStart; var front = (txtarea.value).substring(0,strPos); var back = (txtarea.value).substring(strPos,txtarea.value.length); txtarea.value=front+text+back; strPos = strPos + text.length; if (br == "ie") { txtarea.focus(); var range = document.selection.createRange(); range.moveStart ('character', -txtarea.value.length); range.moveStart ('character', strPos); range.moveEnd ('character', 0); range.select(); } else if (br == "ff") { txtarea.selectionStart = strPos; txtarea.selectionEnd = strPos; txtarea.focus(); } txtarea.scrollTop = scrollPos; } 

// tooltip positioners
function TT_findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) 
    {
        while (obj.offsetParent) 
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}
function TT_findPosX(obj) {
  var curleft = 0;
  if (obj.offsetParent) 
  {
    while (obj.offsetParent) 
        {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}


