// Aug 2011. Seb Gibbs.
function makeDraggable(a){if(!a)return;a.style.zIndex=topindex++;a.onmousedown=mouseDown;a.ontouchstart=mouseDown}function mouseUp(){if(theObj){theObj.boxShadow="";theObj=null}}function mouseDown(a){theObj=this.style;theObj.zIndex=topindex++;a=a||window.event;var b=a.target||a.srcElement;if(b.id!="bar"){theObj=null;return true}theObj.boxShadow="rgba(1,1,200,0.5) 1px 2px 28px";var c=mouseCoords(a),d=getPos(b);theObj.mouseOffset={x:c.x-d.x,y:c.y-d.y};return false}function getPos(a){var b=-9,c=-9;while(a.offsetParent){b+=a.offsetLeft;c+=a.offsetTop;a=a.offsetParent}b+=a.offsetLeft;c+=a.offsetTop;return{x:b,y:c}}function mouseCoords(a){if(a.touches){var b=a.touches[0];return{x:b.pageX,y:b.pageY}}if(a.pageX||a.pageY){return{x:a.pageX,y:a.pageY}}return{x:a.clientX+document.body.scrollLeft-document.body.clientLeft,y:a.clientY+document.body.scrollTop-document.body.clientTop}}function mouseMove(a){if(theObj){a=a||window.event;var b=mouseCoords(a);theObj.left=b.x-theObj.mouseOffset.x+"px";theObj.top=b.y-theObj.mouseOffset.y+"px";return false}return true}function closemypop(a){if(a==null)var b=win.id;else var b=a;toggle(b);setTimeout("var tmp=document.getElementById('"+b+"');tmp.parentNode.removeChild(tmp);win=false",800)}function mypopfin(a){if(a.readyState==2)document.body.style.cursor="default";else if(a.readyState==3){if(a.responseText.length>20)win.innerHTML=a.responseText}else if(a.readyState==4){win.innerHTML=a.responseText;win.style.cursor="default";document.body.style.cursor="default";if(a.status!=200){alert("Note: There was a problem fetching the window:\n"+a.statusText)}delete a;win=false;if(window.XMLHttpRequest)a=new XMLHttpRequest;else if(window.ActiveXObject)a=new ActiveXObject("Microsoft.XMLHTTP");a.onreadystatechange=function(){mypopfin(a)}}}function mypop(a,b){b=b||window.event;winid="thiswin"+a;if(document.getElementById(winid)){closemypop(winid);return false}if(win==false){win=true;req.open("GET",a,true);req.setRequestHeader("ajax","yes");req.send("")}else{setTimeout(function(){mypop(a,b)},1e3);return false}createwin(b);win.setAttribute("id",winid);makeDraggable(win);win.innerHTML="<div class='content ajax' id=bar>Waiting for server.<br>Please wait...</div>";setTimeout("toggle('"+winid+"')",50);return false}function createwin(a){document.body.style.cursor="progress";var b=8,c=100;if(a.pageX||a.pageY){b=a.pageX;c=a.pageY}else if(a.clientX||a.clientY){b=a.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;c=a.clientY+document.body.scrollTop+document.documentElement.scrollTop}b-=120;if(b<30)b=30;winxx=screen.width;if(winxx<9)winxx=window.innerWidth;if(winxx<9)winxx=document.body.clientWidth;if(b-winxx>0)b=winxx-450;if(b<1)b=1;if(b>400)b=400;if(c<50)c=50;win=document.createElement("div");winstyle=win.style;winstyle.display="none";winstyle.minWidth="150px";winstyle.maxWidth="620px";winstyle.zIndex=9;winstyle.cursor="progress";if(a!="here"){winstyle.position="absolute";winstyle.top=c+"px";winstyle.left=b+"px"}if(a!="here")document.body.appendChild(win);else document.getElementById("content").appendChild(win)}function framepop(a,b,c){thehtml="<div style='width:990px;height:400px'><iframe src='"+a+"' style='width:100%;height:100%'></iframe></div>";var d="thiswin"+a;htmlpop(thehtml,d,b,c);return false}function htmlpop(a,b,c,d){createwin(d);win.innerHTML='<div class="content ajax"><img align="right" src="img/close.gif" onclick="closemypop(\''+b+'\')" style="cursor:pointer"><h2 class="title" id="bar">'+c+'</h2><div style="background:rgba(252,252,252,0.9); padding:5px">'+a+"</div></div>";win.setAttribute("id",b);win.style.maxWidth="1300px";makeDraggable(win);win.style.cursor="default";win=false;setTimeout("toggle('"+b+"')",99);document.body.style.cursor="default";return false}function toggle(a){function f(){if(c>0){c-=10;b.opacity=c/100;b.filter="alpha(opacity="+c+")";var a=c/180+.7;if(a>1)a=1;b.webkitTransform="scale("+a+") rotateX("+(c-100)*2+"deg)";d=setTimeout(f,25)}else{b.display="none";d=false}}function e(){if(c<100){c+=10;var a=c/180+.7;if(a>1)a=1;b.opacity=c/100;b.filter="alpha(opacity="+c+")";d=setTimeout(e,25);b.webkitTransform="rotate("+(50-a*50)+"deg) scale("+a+")"}else{b.opacity=1;b.webkitTransform="rotate(0deg) scale(1)";b.filter=null;d=false}}var b,c,d=false;if(d!=false){setTimeout(function(){toggle(a)},250);return}d=true;b=document.getElementById(a).style;if(b.display=="none"){c=0;b.opacity=0;b.filter="alpha(opacity=0)";b.display="block";b.webkitTransform="rotate(-50deg)) scale(0)";e()}else{c=100;f()}}var win=false,req=false;if(window.XMLHttpRequest)req=new XMLHttpRequest;else if(window.ActiveXObject)req=new ActiveXObject("Microsoft.XMLHTTP");req.onreadystatechange=function(){mypopfin(req)};var theObj=null;if(!topindex)var topindex=10;document.onmousemove=mouseMove;document.onmouseup=mouseUp;document.ontouchmove=mouseMove;document.ontouchend=mouseUp
