currentHandler=null;
centeredObjectId="";
openObj=new Array();
openObjHeight=null;
openTimer=null;
closeObj=new Array();
closeObjHeight=null;
closeTimer=null;
resizeObj=new Array();
resizeObjHeight=null;
resizeObjCurrentHeight=null;
resizeObjWidth=null;
resizeTimer=null;
resizeObjContents=new Array();
fullresizeObj=new Array();
fullresizeObjHeight=null;
fullresizeObjWidth=null;
fullresizeTimer=null;
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="";

Array.prototype.find = function(searchStr) {
    var index = -1;
    var i=0;
    while(index<0 && i<this.length) {
        if (this[i]===searchStr) index=i;
        i++;
    }
    return index;
}
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 gotoUrl(url) {
    if(typeof(FacebookUserID) != 'undefined') {
        if (!url.match(/\?/)) {
            url+="?";
            url+="facebook_session_key="+FacebookSessionKey;
        }else{
            url+="&facebook_session_key="+FacebookSessionKey;
        }
        url+="&facebook_userId="+FacebookUserID;
        url+="&auth_token="+FacebookAuthToken;
        url+="&f=1";
    }
    window.location=url;
}
function removeTheNode(idname)
{
    if (document.getElementById(idname)!=null)
    {
        if (fullresizeContainer[0]==document.getElementById(idname)) {
            cancelResize();
        }
        thisNode=document.getElementById(idname);
        thisNode.parentNode.removeChild(thisNode);
    }
    sizeFader();
}
function returnRoundedBox(id,title,content,centerText,zindex,width,removeWhichArray,withClose,withoutFadeDown) {
	output="<table id=\""+id+"\" cellpadding=\"0\" cellspacing=\"0\" style=\"position:absolute;z-index:"+zindex+";width:"+width+"px\" width=\""+width+"px\"><tr><td class=\"roundedCorners\"><img src=\"/skin/tl.png\" /></td><td class=\"roundedTop\" width=\"100%\">&nbsp;</td><td class=\"roundedCorners\"><img src=\"/skin/tr.png\" /></td></tr><tr><td class=\"roundedLeft\">&nbsp;</td><td class=\"roundedContent\" style=\"text-align:"+(centerText?"center":"left")+"\"><h2>";
	
    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.gif\" onmouseout=\"javascript:this.src='/skin/close.gif'\" onmouseover=\"javascript:this.src='/skin/closeover.gif'\" style=\"cursor:pointer;float:right;margin:2px;\" alt=\"Close\" onclick=\"";
        if (!withoutFadeDown || withoutFadeDown==null) {
            output+="startFadeDown();";
        }
        output+="removeTheNode('"+id+"');"+removeThese+"\" />";
    }
    output+=title+"</h2>"+content;
	output+="</td><td class=\"roundedRight\">&nbsp;</td></tr><tr><td class=\"roundedCorners\"><img src=\"/skin/bl.png\" /></td><td class=\"roundedBottom\" width=\"100%\">&nbsp;</td><td class=\"roundedCorners\"><img src=\"/skin/br.png\" /></td></tr></table>";
	return output;
}
function pasteRawHTML(theHTML,destinationObj)
{
    var hiddenArea=null;
    if (document.getElementById("ParseArea")==null)
    {
        hiddenArea=document.createElement("div");
        hiddenArea.style.display="none";
        hiddenArea.ID="ParseArea";
    }
    else
    {
        hiddenArea = document.getElementById("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 getWindowHeight()
{
    var myHeight = ( typeof( window.innerWidth ) == 'number' )?window.innerHeight:( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )?document.documentElement.clientHeight:document.body.clientHeight;
    return myHeight;
}
function getWindowWidth()
{
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' )
    {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    }
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
    {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    }
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
    {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return myWidth;
} 
function centerObject(obj)
{
    var st = (window.pageYOffset)?(window.pageYOffset):(document.documentElement)?document.documentElement.scrollTop:document.body.scrollTop;
    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 hexify(ip)
{
    op="";
    for (c=0;c<ip.length;c++)
    {
        theChar=ip.substr(c,1);
        val=theChar.charCodeAt(0);
        hex=val.toString(16);
        if (hex.length<2)
        {
            hex="0"+hex.toString();
        }
        op+=hex;
    }
    return op;
}
function getOffsetXY(obj)
{
    var curleft = curtop = 0;
    if (obj.offsetParent)
    {
        curleft = obj.offsetLeft;
        curtop = obj.offsetTop;
        while (obj = obj.offsetParent)
        {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        }
    }
    return new Array(curleft,curtop);
}
function getScrollXY()
{
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' )
    {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    }
    else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
    {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    }
    else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
    {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    //pasteRawHTML(scrOfY+"<br />",document.body);
    return [ scrOfX, scrOfY ];
}
function setInnerHTML(obj,content) {
	if (typeof(obj)=="string") {
    	thisresize=document.getElementById(obj);
	}else{
		thisresize=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);
    }
	//pasteRawHTML("<div>"+document.body.scrollHeight +" - "+document.body.clientHeight+"</div>",document.body);
//	if (thisObj.id=="editregion") {
//		b=null;
//		if (document.documentElement) {
//			b=document.documentElement;
//		}else{
//			b=document.body;
//		}
//		b.scrollTop=b.scrollHeight;
//	}
}
function setInnerHTMLCentered(obj,content,container) {
    thisresize=document.getElementById(obj);
    if (thisresize.tagName=="DIV" || thisresize.tagName=="TD") {
        //thisresize.innerHTML=fullresizeObj.length+" in queue";
        fullresizeContainer.push(document.getElementById(container));
        fullresizeObj.push(thisresize);
        fullresizeObjContents.push(content);
        if (fullresizeObj.length==1) startResizeCentered();
    }else{
        thisresize.innerHTML=content;
    }
    //pasteRawHTML(fullresizeObj.length+" setInnerHTML of "+obj+" to "+content+" - ",document.body);
}
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.overflow="visible";
                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";
                centerObject(fullresizeContainer[0]);
                fullresizeTimer = setTimeout("resizeTheObjCentered()",2);
            }
        }
    //pasteRawHTML(fullresizeObj.length+" "+thisObj.id+" resizing - ",document.body);
    }else{
        clearTimeout(fullresizeTimer);
        fullresizeTimer=null;
    }
    
}
function cancelResize() {
    //pasteRawHTML(" "+fullresizeObj.length+" cancelled - ",document.body);
    fullresizeObj[0].innerHTML="Cancelling";
    clearTimeout(fullresizeTimer);
    fullresizeTimer=null;
    fullresizeObj.shift();
    fullresizeObjContents.shift();
    fullresizeContainer.shift();
    if (fullresizeObj.length>0) startResizeCentered();
}
function alert2(comment) {
    drawAlertBlock();
    fader(document.getElementById("alertBack"),80);
    if (!comment.match("/img src/")) {
        comment+="<br /><br /><img src=\"/skin/ok.png\" style=\"cursor:pointer\" onmouseover=\"this.src='/skin/okOver.png'\" onmouseout=\"this.src='/skin/ok.png'\" onclick=\"removeTheNode('alertBack');removeTheNode('alerter')\" />";
    }
    pasteRawHTML(returnRoundedBox("alerter","",comment,true,91,null,false,true),document.body);
    centerObject(document.getElementById("alerter"));
}
function drawAlertBlock()
{
    pasteRawHTML("<div id=\"alertBack\" style=\"visibility:visible;position:absolute;z-index:90;background-color:#94a0b3;padding:0px;margin:0px;top:0px;left:0px;width:100%;height:100%\" onmouseover=\"removeTheNode('shortlist')\">&nbsp;</div>",document.body);
    var docHeight=(typeof document.height != 'undefined')?document.height:(document.compatMode && document.compatMode != 'BackCompat')?document.documentElement.scrollHeight:document.body.scrollHeight;
    var wh=getWindowHeight();
    if (docHeight<wh) docHeight=wh;
    obj=document.getElementById("alertBack");
    obj.style.height=docHeight+"px";
}
function encodeSafe(ip) {
    value=encodeURI(ip);
    //value=value.replace("'","#39");
    value=value.replace("&","(amp)");
    return value;
}
function showUpload(gallery,ref,maxfiles) {
	withoutFader=false;
	if (document.getElementById("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="Nothing much";
	toInsert="<div style=\"width:300px;height:"+h+"px;overflow:hidden\">"+toInsert+"</div>";
	toInsert=returnRoundedBox("uploading","Image upload",toInsert,true,20,310,"",true,withoutFader);
    pasteRawHTML(toInsert,document.body);
    centerObject(document.getElementById("uploading"));
}
function galleryUploaded(gallerytype,ref) {
	if (document.getElementById("editregion")==null) startFadeDown();
	removeTheNode("uploading");
	reloadGallery(gallerytype,ref);
	//Reload the gallery
}
function removeImage(gallerytype,ref,id) {
	currentGallery=document.getElementById("gallery"+gallerytype+ref);
	sendPostRequest("/index.php","cmd=removeimage&gallerytype="+gallerytype+"&ref="+ref+"&id="+id,galleryReceived);
}
var currentGallery=null;
function reloadGallery(gallerytype,ref) {
	currentGallery=document.getElementById("gallery"+gallerytype+ref);
	setInnerHTML(currentGallery.id,currentGallery.innerHTML+"<img src=\"/skin/loading.gif\" />");
	sendPostRequest("/index.php","cmd=gallery&gallerytype="+gallerytype+"&ref="+ref,galleryReceived);
}
function galleryReceived(reply) {
	setInnerHTML(currentGallery.id,reply);
	currentGallery=null;
}
function embeduploader(theCommand,completedHandler,maxfiles) {
    params=new Array();
    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);
    //return "<textarea cols=\"50\" rows=\"20\">"+flashCode("/skin/uploader.swf",params,vars)+"</textarea>";
}
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="empty";
    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];
 }
