currentHandler=openObjHeight=openTimer=closeObjHeight=closeTimer=resizeObjHeight=resizeObjCurrentHeight=resizeObjWidth=resizeTimer=fullresizeObjHeight=fullresizeObjWidth=fullresizeTimer=null;
centeredObjectId="";
openObj=new Array();
closeObj=new Array();
resizeObj=new Array();
resizeObjContents=new Array();
fullresizeObj=new Array();
maxResizeStep=10;
fullresizeObjContents=new Array();
fullresizeContainer=new Array();
currentRequests=new Array();
currentHandlers=new Array();
var countryCode="";
var clubCode="";
var countyCode="";
var selectingCourses=false;
var selectedPictureHandler=null;
var richTextPrefix="";

if(!Array.indexOf){
	Array.prototype.indexOf = function(obj){
		for(var i=0; i<this.length; i++){
			if(this[i]==obj){
				return i;
			}
		}
		return -1;
	}
}

function isdefined(variable){
    return (typeof(window[variable]) == "undefined")?  false: true;
}

function noReturn(e){
    var rval=true;
    if (window.event) keycode=window.event.keyCode;
    else if (e) keycode=e.which;
    if (keycode==13) rval=false;
    return rval;
} 
function removeTheNode(idname) {
	if (typeof(idname)=="string") {
		if (ob(idname)!=null) {
			if (fullresizeContainer[0]==ob(idname)) cancelResize();
			thisNode=ob(idname);
			thisNode.parentNode.removeChild(thisNode);
		}
	}else{
		idname.parentNode.removeChild(idname);
	}
    sizeFader();
}
function rRB(id,title,content,centerText,zindex,width,removeWhichArray,withClose,withoutFadeDown) {
	output="<div id=\""+id+"\" style=\"position:fixed;z-index:"+zindex+";width:"+width+"px\" >";
	output+="<b class=\"b1\"></b><b class=\"b2\"></b><b class=\"b3\"></b><b class=\"b4\"></b>";
	output+="<div class=\"blockHeader\">";
    removeThese="";
    if (removeWhichArray!=null) {
        rems=removeWhichArray.split(",");
        if (removeWhichArray!=null) for(i=0;i<rems.length;i++) removeThese+=";removeTheNode('"+rems[i]+"')";
    }
	if (withClose) {
        output+="<img src=\"/skin/close.png\" onmouseout=\"this.src='/skin/close.png'\" onmouseover=\"this.src='/skin/closeover.png'\" style=\"cursor:pointer;float:right;margin:0px;\" alt=\"Close\" onclick=\"";
        if (!withoutFadeDown || withoutFadeDown==null) {
            output+="startFadeDown();";
        }
        output+="removeTheNode('"+id+"');"+removeThese+"\" />";
    }
	output+=title+"</div>";
	output+="<div class=\"blockContent\" style=\"text-align:"+(centerText?"center":"left")+"\">"+content+"</div>";
	output+="<b class=\"bb4\"></b><b class=\"bb3\"></b><b class=\"bb2\"></b><b class=\"bb1\"></b>";
	output+="</div>";
	return output;
}
function simpleRoundedBox(title,content,centerText,width,closeID,withoutFadeDown) {
	output="<div style=\"width:"+width+"px\" >";
	output+="<b class=\"b1\"></b><b class=\"b2\"></b><b class=\"b3\"></b><b class=\"b4\"></b>";
	output+="<div class=\"blockHeader\">";
	if (closeID) {
        output+="<img src=\"/skin/close.png\" onmouseout=\"this.src='/skin/close.png'\" onmouseover=\"this.src='/skin/closeover.png'\" style=\"cursor:pointer;float:right;margin:0px;\" alt=\"Close\" onclick=\"";
        if (!withoutFadeDown || withoutFadeDown==null) {
            output+="startFadeDown();";
        }
        output+="removeTheNode('"+closeID+"');\" />";
    }
	output+=title+"</div>";
	output+="<div class=\"blockContent\" style=\"text-align:"+(centerText?"center":"left")+"\">"+content+"</div>";
	output+="<b class=\"bb4\"></b><b class=\"bb3\"></b><b class=\"bb2\"></b><b class=\"bb1\"></b>";
	output+="</div>";
	return output;
}
function basicBlock(id,title,content,centerText,divStyle,classname) {
	op="<div id=\""+id+"\" ";
	if (classname!=null) op+="class=\""+classname+"\" ";
	op+="style=\""+divStyle+"\">";
	if (title!=null) {
		op+="<b class=\"b1\"></b><b class=\"b2\"></b><b class=\"b3\"></b><b class=\"b4\"></b>";
		op+="<div class=\"blockHeader\">"+title+"</div>";
	}else{
		op+="<b class=\"bb1\"></b><b class=\"bb2\"></b><b class=\"bb3\"></b><b class=\"bb4\"></b>";
	}
	op+="<div class=\"blockContent\" style=\"text-align:"+(centerText?"center":"left")+"\">"+content+"</div>";
	op+="<b class=\"bb4\"></b><b class=\"bb3\"></b><b class=\"bb2\"></b><b class=\"bb1\"></b>";
	op+="</div>";
	return op;
}
function pRH(theHTML,destinationObj) {
    var hiddenArea=null;
    if (ob("ParseArea")==null) {
        hiddenArea=document.createElement("div");
        hiddenArea.style.display="none";
        hiddenArea.ID="ParseArea";
    } else {
        hiddenArea = ob("ParseArea");
    }
    hiddenArea.innerHTML=theHTML;
    for (c=0;c<hiddenArea.childNodes.length;c++) destinationObj.appendChild(hiddenArea.childNodes[c]);
    hiddenArea.innerHTML="";
}
function theSrcElement(e) {
    if (!e) var e = window.event;
    if (e.target) target = e.target
    else if (e.srcElement) target = e.srcElement
    return target;
}
function cO(obj) {
    var scrolls=getScrollXY();
    st=scrolls[1];
	if (obj.style.position=="fixed") st=0;
    var wh = getWindowHeight();
    var t=(obj.clientHeight>wh)?st:((wh-obj.clientHeight)/2)+st;
    if (t<10) t=10;
    l=((document.body.offsetWidth-obj.clientWidth)/2);
    if (l<0) l=0;
    obj.style.left=l+"px";
    obj.style.top=t+"px";
}
function getScrollXY(){
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
}
function sIH(obj,content) {
	thisresize=((typeof(obj)=="string")?ob(obj):obj);
    if (thisresize.tagName=="DIV" || thisresize.tagName=="TD") {
        resizeObj.push(thisresize);
        resizeObjContents.push(content);
        if (resizeObj.length==1) startResize();
    }else{
        thisresize.innerHTML=content;
    }
}
function startResize() {
    if (resizeObj.length>0) {
        thisresize=resizeObj[0];
        resizeObjCurrentHeight=thisresize.offsetHeight;
        testContent="<div id=\"textContent\">"+resizeObjContents[0]+"</div>";
        thisresize.style.height=resizeObjCurrentHeight+"px";
        thisresize.style.overflow='hidden';
        thisresize.style.display='block';
        if (resizeObjContents[0]=="") {
            resizeObjHeight=1;
        }else{
            thisresize.innerHTML=testContent;
            resizeObjHeight=thisresize.childNodes[0].offsetHeight;
        }
        thisresize.innerHTML=resizeObjContents[0];
        resizeTimer = setTimeout("resizeTheObj()",2);
    }
}
function resizeTheObj(){
    maxMovement=50;
    thisObj=resizeObj[0];
    dh=(resizeObjHeight-resizeObjCurrentHeight)/2;
    if (dh>maxMovement) dh=maxMovement;
    if (dh<-maxMovement) dh=-maxMovement;
    dw=0;
    if (dh<1 && dh>-1 && dw<1 && dw>-1) {
        clearTimeout(resizeTimer);
        resizeTimer=null;
        if (thisObj.innerHTML=="") thisObj.style.display="none";
        thisObj.style.overflow="visible";
        thisObj.style.height="";
        resizeObj.shift();
        resizeObjContents.shift();
        if (resizeObj.length>0) startResize();
    }else{
        resizeObjCurrentHeight+=dh;
        thisObj.style.height=resizeObjCurrentHeight+"px";
        resizeTimer = setTimeout("resizeTheObj()",2);
    }
}
function sIHCentered(obj,content,container) {
    thisresize=ob(obj);
    if (thisresize.tagName=="DIV" || thisresize.tagName=="TD") {
        fullresizeContainer.push(ob(container));
        fullresizeObj.push(thisresize);
        fullresizeObjContents.push(content);
        if (fullresizeObj.length==1) startResizeCentered();
    }else{
        thisresize.innerHTML=content;
    }
}
function startResizeCentered() {
    if (fullresizeObj.length>0) {
        thisresize=fullresizeObj[0];
        currentHeight=thisresize.offsetHeight;
        currentWidth=thisresize.offsetWidth;
        thisresize.style.overflow='visible';
        thisresize.style.display='block';
        thisresize.style.height="";
        thisresize.style.width="";
        thisresize.innerHTML=fullresizeObjContents[0];
        fullresizeObjWidth=thisresize.offsetWidth;
        fullresizeObjHeight=thisresize.offsetHeight;
        if (fullresizeObjContents[0]=="") {
            fullresizeObjHeight=1;
            fullresizeObjWidth=1;
        }
        thisresize.style.overflow='hidden';
        thisresize.style.height=currentHeight+"px";
        thisresize.style.width=currentWidth+"px";
        fullresizeTimer = setTimeout("resizeTheObjCentered()",2);
    }
}
function resizeTheObjCentered(){
    if (fullresizeObj.length>0) {
        thisObj=fullresizeObj[0];
        if (thisObj==null) {
            clearTimeout(fullresizeTimer);
            fullresizeTimer=null;
            fullresizeObj.shift();
            fullresizeObjContents.shift();
            fullresizeContainer.shift();
            if (fullresizeObj.length>0) startResizeCentered();
        }else{
            h=thisObj.offsetHeight;
            w=thisObj.offsetWidth;
            dh=(fullresizeObjHeight-h)/2;
            dw=(fullresizeObjWidth-w)/2;
            if (dh<1 && dh>-1 && dw<1 && dw>-1) {
                clearTimeout(fullresizeTimer);
                fullresizeTimer=null;
                if (thisObj.innerHTML=="") thisObj.style.display="none";
                thisObj.style.height="";
                thisObj.style.width="";
                fullresizeObj.shift();
                fullresizeObjContents.shift();
                fullresizeContainer.shift();
                if (fullresizeObj.length>0) startResizeCentered();
            }else{
                thisObj.style.height=(h+dh)+"px";
                thisObj.style.width=(w+dw)+"px";
                cO(fullresizeContainer[0]);
                fullresizeTimer = setTimeout("resizeTheObjCentered()",2);
            }
        }
    }else{
        clearTimeout(fullresizeTimer);
        fullresizeTimer=null;
    }
}
function cancelResize() {
    fullresizeObj[0].innerHTML="Cancelling";
    clearTimeout(fullresizeTimer);
    fullresizeTimer=null;
    fullresizeObj.shift();
    fullresizeObjContents.shift();
    fullresizeContainer.shift();
    if (fullresizeObj.length>0) startResizeCentered();
}
function showUpload(gallery,ref,maxfiles) {
	withoutFader=false;
	if (ob("editregion")!=null) withoutFader=true;
	if (!withoutFader) startFadeUp();
	if (maxfiles==null) maxfiles=1;
	toInsert=embeduploader("gallerytype="+gallery+"&ref="+ref,"galleryUploaded",maxfiles);
	h=(maxfiles*50)+20+25;
	toInsert="<div style=\"width:300px;height:"+h+"px;overflow:hidden\">"+toInsert+"</div>";
	toInsert=rRB("uploading","Image upload",toInsert,true,20,310,"",true,withoutFader);
    pRH(toInsert,document.body);
    cO(ob("uploading"));
}
function galleryUploaded(gallerytype,ref) {
	if (ob("editregion")==null) startFadeDown();
	removeTheNode("uploading");
	if (gallerytype=="avatars") {
		av=ob("myAvatar");
		str = av.src; 
		pattern = /-([0-9]*)\.jpg/; 
		result =  str.match(pattern); 
		for(i = 0; i < result.length; i++) {
			v=(1*result[i])+1;
			str=str.replace("-"+result[i]+".jpg","-"+v+".jpg");
		}
		av.src=str;
	}
}
function embeduploader(theCommand,completedHandler,maxfiles) {
    vars=new Array();
    params.push("width");
    vars.push("300");
    params.push("height");
    vars.push("600");
    params.push("src");
    vars.push("/skin/uploader.swf");
    params.push("quality");
    vars.push("high");
    params.push("align");
    vars.push("middle");
    params.push("play");
    vars.push("true");
    params.push("loop");
    vars.push("true");
    params.push("scale");
    vars.push("showall");
    params.push("wmode");
    vars.push("transparent");
    params.push("devicefont");
    vars.push("false");
    params.push("id");
    vars.push("uploader");
    params.push("name");
    vars.push("uploader");
    params.push("bgcolor");
    vars.push("#ffffff");
    params.push("menu");
    vars.push("false");
    params.push("allowFullScreen");
    vars.push("false");
    params.push("allowScriptAccess");
    vars.push("sameDomain");
    params.push("movie");
    vars.push("/skin/uploader.swf");
    params.push("salign");
    vars.push("");
    params.push("FlashVars");
	fv=theCommand+"&completeHandler="+completedHandler+"&quantity="+maxfiles+"&"+document.cookie.replace(/; /g,"&");
    vars.push(fv);
    return flashCode("/skin/uploader.swf",params,vars);
}
function flashCode(srcMovie,params,vars) {
    op="<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\"";
    for(i=0;i<vars.length;i++) {
        op+=" "+params[i]+"=\""+vars[i]+"\"";
    }
    op+=">";
    for(i=0;i<vars.length;i++) {
        op+="<param name=\""+params[i]+"\" value=\""+vars[i]+"\" />";
    }
    op+="<embed src=\""+srcMovie+"\"";
    for(i=0;i<vars.length;i++) {
        op+=" "+params[i]+"=\""+vars[i]+"\"";
    }
    op+="swLiveConnect=\"true\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
    op+="</object>";
    return op;
}
function getCookieValue(name) {
    reply="";
    var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) reply=c.substring(nameEQ.length,c.length);
	}
	return reply;
}
 function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
 }
function logoff(src) {
	src.innerHTML="Logging off..";
	var vars="cmd=logout";
	sPR("/index.php",vars,refreshPage);
}
function checkvalidinput(src,withSpaces,minlength) {
	val=src.value;
	if (withSpaces) {
    	alpharegex=new RegExp(/^[\.@\/a-zA-Z0-9 ]*$/);
	}else{
    	alpharegex=new RegExp(/^[\.@\/a-zA-Z0-9]*$/);
	}
    ok=alpharegex.test(val);
	if (ok) {
		if (val.length<minlength) {
			src.className="failedinput";
			com="At least "+minlength+" character";
			if (minlength>1) com+="s";
			sIH(src.id+"Alert",com);
			ok=false;
		}else{
			src.className="normalinput";
			sIH(src.id+"Alert","");
		}			
	}else{
		src.className="failedinput";
		sIH(src.id+"Alert","Alphanumeric only");
	}
	return ok;
}
function refreshPage(reply) {
	window.location.reload();
}
function receivedSectionContent(reply) {
	if (reply!="ok" && reply!="") {
		sect=reply.split("<sections>");
		for(i=0;i<sect.length;i++) {
			ss=/^<scripting>/;
			if (ss.test(sect[i])) {
				eval(sect[i].replace('<scripting>',''));
			}else{
				ins=/<inside>/;
				if (ins.test(sect[i])) {
					ip=sect[i].split("<inside>");
					ob(ip[0]).innerHTML=ip[1];
				}else{
					ins=/<insert>/;
					if (ins.test(sect[i])) {
						ip=sect[i].split("<insert>");
						ats=/^<appendtostart>/;
						cont=null;
						if (ats.test(ip[0])) {
							ip[0]=ip[0].replace('<appendtostart>','');
							if (cont=ob(ip[0])) ip[1]+=cont.innerHTML;
						}
						ats=/^<appendtoend>/;
						cont=null;
						if (ats.test(ip[0])) {
							ip[0]=ip[0].replace('<appendtoend>','');
							if (cont=ob(ip[0])) ip[1]=cont.innerHTML+ip[1];
						}
						if (cont==null) cont=ob(ip[0]);
						if (cont!=null) {
							if (ip[0]=="dialog") {
								sIHCentered(ip[0],ip[1],ip[0]);
							}else{
								sIH(cont,ip[1]);
							}
						}
					}else{
						rep=/<replace>/;
						if (rep.test(sect[i])) {
							ip=sect[i].split("<replace>");
							if (src=ob("block"+ip[0])) {
								pRH("<div id=\"tempcontainer\" style=\"display:none\">"+ip[1]+"</div>",document.body);
								newsrc=ob("tempcontainer").childNodes[0];
								src.parentNode.insertBefore(newsrc,src);
								removeTheNode(src);
								removeTheNode("tempcontainer");
							}
						}else{
							alert(reply);
						}
					}
				}
			}
		}
	}
}
function checkAlphaNumeric(e) {
    if (window.event) {
        e=window.event;
        keycode=window.event.keyCode;
    }else{
        keycode=e.which;
    }
	asc=e.charCode || e.keyCode;
	c=String.fromCharCode(asc);
	valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789.,@/";
	reply=false;
	if (valid.indexOf(c)>=0) reply=true;
	if (keycode==190 || keycode==110) reply=true;
	if (keycode==9 || keycode==8 || keycode==46 || keycode==36 || keycode==35 || keycode==37 || keycode==39) reply=true;
	return reply;
}
function checkAlphaNumericOnly(e) {
    if (window.event) {
        e=window.event;
        keycode=window.event.keyCode;
    }else{
        keycode=e.which;
    }
	asc=e.charCode || e.keyCode;
	c=String.fromCharCode(asc);
	valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	reply=false;
	if (valid.indexOf(c)>=0) reply=true;
	if (keycode==190 || keycode==110) reply=true;
	if (keycode==9 || keycode==8 || keycode==46 || keycode==36 || keycode==35 || keycode==37 || keycode==39) reply=true;
	return reply;
}
function checkAlphaNumericOnly(e,enterHandler) {
    if (window.event) {
        e=window.event;
        keycode=window.event.keyCode;
    }else{
        keycode=e.which;
    }
	asc=e.charCode || e.keyCode;
	c=String.fromCharCode(asc);
	valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	reply=false;
	if (valid.indexOf(c)>=0) reply=true;
	if (keycode==9) reply=true; //tab
	if (keycode==190 || keycode==110) reply=true;
	if (keycode==8 || keycode==46 || keycode==36 || keycode==35 || keycode==37) reply=true;
	if (keycode==13) enterHandler();
	return reply;
}
function setStatusLine(t) {
	if (t!="") t="&nbsp;|&nbsp;"+t;
	ob("statusline").innerHTML=t;
}
function focusID(id) {
	setTimeout(function(){ob(id).select();},1000);
}
function pressingEnterOrEscape(srcObj,e,enterhandler,escapehandler) {
    if (window.event)
    {
        e=window.event;
        keycode=window.event.keyCode;
    }else{
        keycode=e.which;
    }
	if (keycode==13) enterhandler(srcObj);
	if (keycode==27) escapehandler();
}
function encodeUpload(ip) {
	return ip.replace(/&/g,"(amp)").replace(/=/g,"(eq)").replace(/%/g,"(per)").replace(/\+/g,"(plus)").replace(/ /g,"+");
}
function changeScheme(sch) {
	SetCookie("scheme",sch,365);
	window.location.reload();
}
function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}
function Delete_Cookie( name, path, domain ) {
document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
var removeDroppedObject=false;
function addNewBlock(srcObj,type,defaultname, cust) {
	if (displayByFlash) showNotEmbed();
	box=basicBlock("blocknew"+type,defaultname,"Drop this widget where you want it",true,"width:"+columnWidth+"px","blockclass");
	pRH(box,ob("column0"));
	cO(ob("blocknew"+type));
	dragObject(null,null,ob('blocknew'+type),true);
	removeDroppedObject=true;
}
function attachBlock(srcObj,id) {
	srcObj.parentNode.innerHTML="Attaching...";	
	attachBlockToMe(id);
	sPR("/index.php",vars,receivedSectionContent);
}
function attachBlockToMe(id) {
	vars="cmd=attachBlock&blockid="+id;
	sPR("/index.php",vars,receivedSectionContent);
}
function blockToggle(srcObj,id,persist) {
	opened=true;
	empty=true;
	cont=ob(id);
	if (cont.style.display=='none') opened=false;
	if (cont.children.length>0) empty=false;
	srcObj.className=opened?"opendown":"closeup";
	if (empty && !opened) {
		sIH(cont,"<img src='/skin/loading.gif' align='absmiddle' /> Loading...");
	}else{
		tE(id,false,true,'');
	}
	vars="";
	if (empty) {
		vars="cmd=openBlock&blockid="+id.replace("block","").replace("content","")+(persist?"&opened=1":"");
	}else if(persist) {
		vars="cmd=toggleblock&blockid="+id.replace("block","").replace("content","")+"&opened="+(opened?"0":"1");
	}
	if (vars!="") sPR("/index.php",vars,receivedSectionContent);
}
function ensureOpenBlock(id) {
	if (con=ob("block"+id+"content")) {
		if (con.style.display=='none') blockToggle(ob("block"+id+"Header"),"block"+id+"content",false);
	}		
}
var selectedfeeds=new Array();
function addmultiRSS(srcObj,blockid) {
	ip=ob(srcObj.id+'input');
	feed=ip.value;
	if (feed!="") {
		srcObj.innerHTML='<img src=\"/skin/loading.gif\" align=\"absmiddle\" /> Saving RSS settings...';
		vars="cmd=includefunction&includefile=multirss&handler=addFeed&address="+encodeUpload(feed)+"&blockid="+blockid;
		sPR('/index.php',vars,receivedSectionContent);
	}else{
		alert('Provide a Feed address');
	}
}
function deletemultiRSS(srcObj,blockid) {
	if (window.confirm("Click OK to remove the displayed feed from this block")) {
		srcObj.parentNode.innerHTML='<img src="/skin/loading.gif" align="absmiddle" /> Removing RSS feed...';
		feedid=selectedfeeds[blockid];
		vars='cmd=includefunction&includefile=multirss&handler=removeFeed&feedid='+feedid+'&blockid='+blockid;
		sPR('/index.php',vars,receivedSectionContent);
	}
}
function loadmultiRSS(feedid,blockid) {
	if (feedblock=ob("feed"+blockid)) {
		ins="<div style=\"width:"+feedblock.clientWidth+"px;height:"+feedblock.clientHeight+"px\"><center><img src=\"/skin/loading.gif\" align=\"absmiddle\" /> Loading feed...</center></div>";
		feedblock.innerHTML=ins;
	}
	selectedfeeds[blockid]=feedid;
	sPR('/index.php','cmd=readRSS&feed='+feedid+'&blockid='+blockid,receivedSectionContent);
}
function checkMoveObject() {
	cook=getCookieValue("moveobject");
	if (cook!=null && cook !="") {
		if (showNotEmbed()) {}
		moving=null;
		if (ob("block"+cook)) {
			moving=ob("block"+cook);
		}else if (ob(cook)) {
			moving=ob(cook);
		}
		if (moving) {
			dropThisMessage('Place your new widget')
			dragObject(null,null,moving,true);
		}
	}
}
function toLocalTime(h,m,s,D,M,Y) {
	local=new Date(	Date.UTC(Y,M,D,h,m,s));
}
var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;
function mopen(id){	
	mcancelclosetime();
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	ddmenuitem = ob(id);
	ddmenuitem.style.visibility = 'visible';
}
function mclose(){
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}
function mclosetime(){
	closetimer = window.setTimeout(mclose, timeout);
}
function mcancelclosetime(){
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}
document.onclick = mclose; 

function shopFave(srcObj,shopid,val,cat) {
	srcObj.parentNode.innerHTML="Updating favourites...";
	vars='cmd=shopFave&shopid='+shopid+'&val='+val+'&cat='+cat;
	sPR('/index.php',vars,receivedSectionContent);
}
var selectedFlashBlock="";
function changeFlashBlock(blockid) {
	selectedFlashBlock=blockid;
	f=getFlashMovie('linkPresentation');
	f.selectFlashBlock(blockid);
	buildFlashSelector();
}
function buildFlashSelector() {
	fetchLinks();
	sel=ob("flashSelector");
	ins="";
	inorder=new Array();
	for(ids in linkvariables) inorder.push(linkvariables[ids]);
	inorder.sort(sortByOrder);
	for(i=0;i<inorder.length;i++) {
		//ins+=" "+ids[i];
		if (selectedFlashBlock=="") selectedFlashBlock=inorder[i]["blockid"];
		linked="";
		colstr=getElementStyle("flashSelector","color","color");
		if (colstr.substr(0,1)=="#") {
			col=colstr.replace("#","");
		}else{
			col=rgbStringToHex(colstr);
		}
		if (inorder[i]["linked"]!="0") linked="&nbsp;<img src='/colourize-attach-"+col+".gif' align='absmiddle' title='"+inorder[i]["linkedfrom"]["username"]+"' />";
		//linked=inorder[i]["linked"];
		if (selectedFlashBlock==inorder[i]["blockid"]) {
			ins+="<b>"+inorder[i]["title"]+linked+"</b> ";
		}else{
			ins+="<span onclick='changeFlashBlock("+inorder[i]["blockid"]+")'>"+inorder[i]["title"]+linked+"</span> ";
		}
	}
	sel.innerHTML=ins;
}
function fetchLinks() {
	uid=new RegExp(/avatars_[a-z]*_([0-9]*)_[0-9*]/i);
	snap=new RegExp(/linktitle([0-9]*)/i);
	att=new RegExp(/colourize\-attach/i);
	linkvariables={};
	for(b=0;b<flashedBlocks.length;b++) {
		thisblock={};
		h=c=null;
		bl=ob(flashedBlocks[b]);
		d=bl.getElementsByTagName("DIV");
		for (i=0;i<d.length;i++) {
			if (d[i].className=="blockHeader") h=d[i];
			if (d[i].className=="blockContent") c=d[i];
		}
		if (h!==null && c!==null) {
			thisblock["title"]=h.getElementsByTagName("DIV")[0].innerHTML;
			thisblock["order"]=b;
			thisblock["attach"]=0;
			if (h.innerHTML.match(att)) thisblock["attach"]=1;
			thisblock["blockid"]=flashedBlocks[b].replace("block","");
			linkedfrom={"username":"","avatar":"","linked":""};
			thisblock["linked"]=0;
			if (h.getElementsByTagName("NOBR").length>0) {
				if (h.getElementsByTagName("NOBR")[0].getElementsByTagName("IMG").length>0) {
					u=h.getElementsByTagName("NOBR")[0].getElementsByTagName("IMG")[0];
					if (u.src.match(uid)) {
						linkedfrom["username"]=u.title;
						av=u.src.split("avatars");
						linkedfrom["avatar"]="avatars"+av[1].replace(/_[0-9]*_/,"_60_");
						thisblock["linked"]=1;
						thisblock["linkedfrom"]=linkedfrom;
					}
				}
			}
			thisblock["links"]={};
			l=c.getElementsByTagName("A");
			for(i=0;i<l.length;i++) {
				thislink={"order":"","url":"","snapshot":"","name":""};
				thislink["order"]=i;
				thislink["url"]=l[i].href;
				//ids=l[i].innerHTML.match(snap);
				id=l[i].innerHTML.match(snap)[1];
				thislink["name"]=l[i].getElementsByTagName("H3")[0].innerHTML;
				thislink["snapshot"]=l[i].getElementsByTagName("H3")[0].getAttribute("snapshot");
				thisblock["links"][id]=thislink;
//			for(k in thisblock) {
//				pRH("<div>"+k+" = "+thisblock[k]+"</div>",document.body);
//			}
			}
			
			//pRH(thisblock.join(","),document.body);
			linkvariables[thisblock["blockid"]]=thisblock;
			//alert(thisblock);
		}
	}
	viewer();
}
function getElementStyle(elemID, IEStyleProp, CSSStyleProp) {
    var elem = document.getElementById(elemID);
    if (elem.currentStyle) {
        return elem.currentStyle[IEStyleProp];
    } else if (window.getComputedStyle) {
        var compStyle = window.getComputedStyle(elem, "");
        return compStyle.getPropertyValue(CSSStyleProp);
    }
    return "";
}
function rgbStringToHex(rgb) {
	rgbv=rgb.replace("rgb(","").replace(")","").replace(/ /g,"").split(",");
	r=rgbv[0]*1;
	g=rgbv[1]*1;
	b=rgbv[2]*1;
	rr=r.toString(16);
	if (rr.length==1) rr="0"+rr;
	gg=g.toString(16);
	if (gg.length==1) gg="0"+gg;
	bb=b.toString(16);
	if (bb.length==1) bb="0"+bb;
	c=rr+gg+bb;
	return c;
}
function sortByOrder(a,b) {
	return a["order"]-b["order"];
}
function userDialog(title,handler) {
	ins="<div id='dialogContent'><img src='/skin/loading.gif' align='absmiddle' />&nbsp;Loading...</div>";
	ins=rRB('dialogBox',title,ins,false,5,400,null,true,false);
	startFadeUp();
	pRH(ins,document.body);
	cO(ob("dialogBox"));
	vars='cmd=userfunction&handler='+handler;
	sPR('/index.php',vars,userDialogLoaded);	
}
function userDialogLoaded(reply) {
	bits=reply.split("<sections>");
	sIHCentered('dialogContent',bits[0],'dialogBox');
	if (bits.length>1) {
		for (i=1;i<bits.length;i++) receivedSectionContent(bits[i]);
	}
}
function addBlockType(srcObj,type) {
	srcObj.parentNode.innerHTML="<img src='/skin/loading.gif' align='absmiddle' /> Adding widget...";
	vars="cmd=addBlock&type="+type;
	sPR('/index.php',vars,receivedSectionContent);
}
function progFave(srcObj,tit,add) {
	srcObj.src='/skin/loading.gif';
	doit="&"+((add==0)?"remove":"add")+"="+tit;
	sPR('/index.php','cmd=includefunction&includefile=iplayer&handler=returnLoadListing'+doit,receivedSectionContent);
}
function toggleTab(srcObj,tarid) {
	tar=ob(tarid);
	if (closeStatusTimer!=null) cancelStatTimer();
	srcObj.className=((tar.style.display=="none")?"tabclose":"tabopen");
	tE(tar.id,true,false,otherTabs(tarid));
}
function openUpdates() {
	tar=ob("statusUpdates");
	if (tar.style.display=="none") {
		ob("statOpener").className=((tar.style.display=="none")?"tabclose":"tabopen");
		tE("statusUpdates",true,false,'');
	}
}
function closeUpdates() {
	if (closeStatusTimer!=null) cancelStatTimer();
	tar=ob("statusUpdates");
	if (tar.style.display!="none") {
		ob("statOpener").className=((tar.style.display=="none")?"tabclose":"tabopen");
		tE("statusUpdates",true,false,'');
	}
}
function otherTabs(tab) {
	o=["statusUpdates","messageUpdates"];
	r=new Array();
	for(i=0;i<o.length;i++) {
		if (o[i]!=tab) {
			if (r!="") r+=",";
			r+=o[i]+":1:0";
		}
	}
	return r;
}
var closeStatusTimer=null;
function startCloseUpdateTimer() {
	closeStatusTimer=setTimeout("closeUpdates()",10000);
}
function cancelStatTimer() {
	clearTimeout(closeStatusTimer);
	closeStatusTimer=null;
}
var commentingOn=null;
function statusReply(id) {
	if (commentingOn!=null) sIH(commentingOn,"");
	commentingOn=ob("replyto"+id);
	ins="<textarea id='commentReply' class='normalinput' style='width:270px;font-size:10px;display:block;margin:5px auto;height:auto;min-height:20px' onkeydown='checkforurls(this,event)' onkeyup='drawStatusLength(this,true)'></textarea><center><div class='buttonDiv' onclick='commentOnStatus(this,\"commentReply\","+id+")'>Post</div></center>";
	ins+="<span id='commentReplyLength'></span><div id='commentReplyTab'></div>";
	sIH(commentingOn,ins);
}
var postStatusTo=new Array();
var postmaxlength=512;
function tickOutput(srcObj,bid,inc,postlength) {
	if (srcObj.className=="cantick") {
		postStatusTo.push([bid,postlength]);
		srcObj.className="isticked";
	}else{
		for(i=postStatusTo.length-1;i>=0;i--) {
			if (postStatusTo[i][0]==bid) postStatusTo.splice(i,1);
			srcObj.className="cantick";
		}
	}
	calcMaxLength();
}
function calcMaxLength() {
	postmaxlength=512;
	for(i=postStatusTo.length-1;i>=0;i--) {
		if (postmaxlength>postStatusTo[i][1]) postmaxlength=postStatusTo[i][1];
	}
	drawStatusLength(ob("newStatus"),false);
}
var notReachedMax=false;
var shrunkLinks=new Array();
function checkforurls(src,e) {
    if (window.event) keycode=window.event.keyCode;
    else if (e) keycode=e.which;
    if (keycode==32) findURLs(src.id);
}
function drawStatusLength(src,defaultLength) {
	t=src.value;
	l=encodeHTMLStatus(t).length;
	if (!defaultLength) {
		if (l>postmaxlength) src.value=t.substr(0,postmaxlength);
		l=encodeHTMLStatus(src.value).length;
		ob(src.id+"Length").innerHTML=l+"/"+postmaxlength+" characters";
	}else{
		if (l>512) src.value=t.substr(0,512);
		l=encodeHTMLStatus(src.value).length;
		ob(src.id+"Length").innerHTML=l+"/512 characters";
	}
}

function findURLs(ip) {
	shrunkLinks=new Array();
	t=ob(ip).value;
	ins="";
	if (urls=getUrlsInString(t)) {
		for(f=0;f<urls.length;f++) {
			if (!urls[f].match(/http:\/\/l2l.at/gim)) {
				urls[f]=trim(urls[f]);
				shrunkLinks.push([urls[f],""]);
			}
		}
		for(s=0;s<shrunkLinks.length;s++) ins+="<div id='url"+s+"' class='msg'>"+shrunkItem(s,ip)+"</div>";
	}
	pre="";
	if (ins!="") {
		if (shrunkLinks.length>1) {
			pre="Shrink these links?";
		}else{
			pre="Shrink this link?";
		}
		ins="<div class='expand' style='padding:2px;margin:2px'>"+pre+ins+"</div>";
	}
	sIH(ip+"Tab",ins);
}
function shrunkItem(s,ip) {
	ins=shrunkLinks[s][0];
	if (shrunkLinks[s][1]=="") {
		ins+="<nobr class='blockLink' onclick='shrink(this,\""+s+"\",\""+ip+"\")'>Shrink</nobr>";
	}else{
		ins+="<br />"+shrunkLinks[s][1];
	}
	return ins;
}
function encodeHTMLStatus(ip) {
	return ip.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/'/g,'&rsquo;').replace(/"/g,'&rdquo;');
}
function sendStatuses(srcObj,reply) {
	status=encodeUpload(encodeHTMLStatus(ob("newStatus").value));
	vars="cmd=updateStatuses&content="+status+"&others=";
	others="";
	for(o=0;o<postStatusTo.length;o++) {
		if (others!="") others+=";";
		others+=postStatusTo[o][0];
	}
	vars+=others;
	if (reply!=0) vars+="&replyto="+reply;
	sPR('/index.php',vars,receivedSectionContent);
	showLoading('statCont',"Processing...");
}
function commentOnStatus(srcObj,ipObj,replyto) {
	status=encodeUpload(encodeHTMLStatus(ob(ipObj).value));
	vars="cmd=updateStatuses&content="+status+"&replyto="+replyto;
	sPR('/index.php',vars,receivedSectionContent);
	showLoading('statCont',"Processing...");
}
function hideFeed(un) {
	vars="cmd=updateStatuses&hide="+un;
	sPR('/index.php',vars,receivedSectionContent);
	showLoading('statCont',"Processing...");
}
function getUrlsInString(s) {
	s+=" ";
	return s.match(/(http:\/\/[\w#!:.?+=&%@!\-\/]*?) /gim);
}
var editingValue=null;
function shrink(srcObj,s,ip) {
	editingValue=ip;
	url=shrunkLinks[s][0];
	par=srcObj.parentNode;
	par.innerHTML="Shrinking...";
	L2Lshrink(url,"beenshrunk",'From Musterfy');
}
function beenshrunk(reply) {
	if (reply["error"]) {
		alert(reply["error"]);
	}else if (reply["url"]) {
		t=ob(editingValue).value;
		t=t.replace(trim(reply["longurl"]),reply["url"]);
		ob(editingValue).value=t;
	}
	findURLs(editingValue);
	drawStatusLength(ob(editingValue),(editingValue!="newStatus"));
}
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
function trim( value ) {
	return LTrim(RTrim(value));
}
function toggleConversation(convid,loadconv) {
	tar=ob("conv"+convid);
	if (tar.style.display=="none") {
		if (loadconv) {
			serverFunction(ob("conv"+convid).childNodes[0],"Loading...","cmd=thisuser&handler=wholeConversation&convid="+convid)
		}else{
			send=false;
			for(k=0;k<tar.childNodes.length;k++) {
				kid=tar.childNodes[k];
				if (kid.className=="unread") send=true;
			}
			if (send) sPR('/index.php','cmd=thisuser&handler=markasread&convid='+convid,receivedSectionContent);
		}
	}else{
		for(k=0;k<tar.childNodes.length;k++) {
			kid=tar.childNodes[k];
			if (kid.className=="unreadmsg") kid.className="readmsg";
		}
	}
	tE("conv"+convid,false,true,'');
}
function wc() {
	return window.confirm("Are you sure?");
}
function showLoading(srcObj,message) {
	if (typeof(srcObj)=="string") srcObj=ob(srcObj);
	w=srcObj.clientWidth;
	h=srcObj.clientHeight;
	ins="<table cellspacing=0 cellpadding=0><tr><td style='width:"+w+"px;height:"+h+"px;text-align:center;vertical-align:middle'><img src='/skin/loading.gif' />";
	if (message!="") ins+="<br>"+message;
	ins+="</td></tr></table>";
	srcObj.innerHTML=ins;
}
function serverFunction(srcObj,message,vars) {
	if (srcObj) showLoading(srcObj.parentNode,message);
	sPR('/index.php',vars,receivedSectionContent);
}
function dialog(title,cmd,vars) {
	ins=rRB('dialog',title,'<img src="/skin/loading.gif" />',true,5,400,'',true,false);
	startFadeUp();
	pRH(ins,document.body);
	cO(ob("dialog"));
	sPR('/index.php','cmd='+cmd+'&'+vars,receivedSectionContent);
}
function linkjsfile(filename){
  var fileref=document.createElement('script');
  fileref.setAttribute("type","text/javascript");
  fileref.setAttribute("src", filename);
  document.getElementsByTagName("head").item(0).appendChild(fileref);
}
// Messaging
var selectedrecipients=new Array();
function recipientList() {
	reply="";
	for(i=0;i<myFriends.length;i++) {
		if (selectedrecipients.indexOf(myFriends[i]["id"])>=0) {
			reply+="<div class=\"recipient\" title=\""+myFriends[i]["username"]+"\">"+myFriends[i]["name"]+" | <span class=\"blockLink\" onclick=\"removeRecipient('"+myFriends[i]["id"]+"')\">X</span></div>";
		}
	}
	ob("Listrecipients").innerHTML=reply;
}
function removeRecipient(id) {
	i=selectedrecipients.indexOf(id);
	selectedrecipients.splice(i,1);
	recipientList();
}
function findFriends(srcObj,e) {
	scored=new Array();
	val=srcObj.value;
	for(i=0;i<myFriends.length;i++) {
		if (selectedrecipients.indexOf(myFriends[i]["id"])<0) {
			scored.push(new Array(searchScore(val,myFriends[i]),myFriends[i]));	
		}
	}
	scored.sort(sortByScore);
	scored.reverse();
	maxf=scored.length;
	if (maxf>10) maxf=10;
	fcontent=new Array();
	for(f=0;f<maxf;f++) if (scored[f][0]>0) fcontent.push(scored[f][1]["id"]+"-datasplit-"+scored[f][1]["name"]+" <em>["+scored[f][1]["username"]+"]</em>");
	content=fcontent.join("-optionsplit-");
	checkShortlistKeys(srcObj,e,addRecipient,null,true,content);
}
function sortByScore(a,b)
{
return a[0] - b[0];
}
function searchScore(val,person) {
	score=0;
	vals=val.split(" ");
	names=person["name"].split(" ");
	for(v=0;v<vals.length;v++) {
		for(n=0;n<names.length;n++) {
			score+=scoreMatch(vals[v],names[n]);
		}
		score+=scoreMatch(vals[v],person["username"]);
	}
	return score;
}
function scoreMatch(val,word) {
	s=0;
	if (word!="" && val!="") {
		eval("m=/^"+val+"/i;");
		if (m.test(word)) {
			s+=10;
		}else{
			eval("m=/"+val+"/i;");
			if (m.test(word)) s+=5;
		}
	}
	return s;
}
function addRecipient(id) {
	if (id!=null) {
		selectedrecipients.push(id);
		recipientList();
		ob("friendSearch").value="";
	}
}