function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

var aSliding=new Array();
var aSlidingInterval=new Array();

function SlideLayer (sLayer,nX,nMaxX,slideType) {
	
		clearInterval(aSlidingInterval[sLayer]);
		aSliding[sLayer]='';
	
		obj=MM_findObj(sLayer);
		
		nLeft=parseInt(obj.style.left);
		
		if ((slideType == 'right') && (nLeft < nMaxX) && !aSliding[sLayer]) {
			obj.style.left=nLeft+5+'px';
			aSliding[sLayer]=slideType;
			aSlidingInterval[sLayer]=setInterval("RunningSlider('"+sLayer+"',"+nX+","+nMaxX+",'"+slideType+"')",10);
		}
		else	if ((slideType == 'left') && (nLeft > nX) && !aSliding[sLayer]) {
			obj.style.left=nLeft-5+'px';
			aSliding[sLayer]=slideType;
			aSlidingInterval[sLayer]=setInterval("RunningSlider('"+sLayer+"',"+nX+","+nMaxX+",'"+slideType+"')",10);
		}
		//else
		//	aSliding[sLayer]='';
}

function RunningSlider (sLayer,nX,nMaxX,slideType) {
		obj=MM_findObj(sLayer);
		
		nLeft=parseInt(obj.style.left);
		
		if ((slideType == 'right') && (aSliding[sLayer]=='right') && (nLeft < nMaxX)) {
			obj.style.left=nLeft+5+'px';
		}
		else	if ((slideType == 'left') && (aSliding[sLayer]=='left') && (nLeft > nX)) {
			obj.style.left=nLeft-5+'px';
		}
		else {
			aSliding[sLayer]='';
			clearInterval(aSlidingInterval[sLayer]);
		}
}

function AjaxObject()
{
  var ro;

  if (window.XMLHttpRequest) {  ro = new XMLHttpRequest(); }
  else {
    ro = new ActiveXObject('Msxml2.XMLHTTP');
    if(!ro) { ro = new ActiveXObject('Microsoft.XMLHTTP'); }
  }

  return ro;
}

var http = AjaxObject();

function AjaxSendRequest(action,vars,handler) {
	
	CenterLayer ('progress',362,86,window.document);
	obj=MM_findObj('progress');
	if (obj)
		obj.style.visibility='visible';
	
    http.open('get', action+'&rnd='+Math.random());
    if (!handler)
    	handler=handleResponse;
    http.onreadystatechange = handler;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4) {
        var response = http.responseText;
        if (response) {
        	
        	obj=MM_findObj('progress');
			if (obj)
				obj.style.visibility='hidden';
        	
           	obj=MM_findObj('chooseblock');
           	if (obj)
           		obj.innerHTML=response;
           		
          	
           	obj=MM_findObj('needtbl');
			y=findPosY(obj);
		
			obj1=MM_findObj('fl_leader');
			obj1.style.top=y+30;
			
			obj1=MM_findObj('fl_outpaint');
			obj1.style.top=y+30+159+30-11;
			
			obj1=MM_findObj('fl_colouring');
			obj1.style.top=y+30+159+30+310-15;
			
			SetCopyPosition();
        }
     }
}

function 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 PaintHandleResponse() {
    if(http.readyState == 4) {
        var response = http.responseText;
        if (response) {
        	
        	obj=MM_findObj('progress');
			if (obj)
				obj.style.visibility='hidden';
        	
           	obj1=MM_findObj('fl_paintcont');
           	
           	obj=MM_findObj('fl_paint');
           	if (obj) {
           		obj.innerHTML=response;
           		obj1.style.visibility='visible';
           		window.scrollTo(0,520);
           	}
           	SetCopyPosition();
        }
     }
}

function PaintNotesHandleResponse() {
    if(http.readyState == 4) {
        var response = http.responseText;
        if (response) {
        	
        	obj=MM_findObj('progress');
			if (obj)
				obj.style.visibility='hidden';
        	
           	obj=MM_findObj('paintnotes');
           	if (obj) {
           		obj.innerHTML=response;
           	}
           	SetCopyPosition();
        }
     }
}



var atText1 = "<img src=i/alt_angle1.png width=80 height=25 style=top:1px;position:relative><table border=0";
var atText2 = " cellspacing=1 cellpadding=10 bgcolor='#e0e0e0' width=200><tr><td bgcolor='#ffe8bc' class=snoska>";
var atText3 = "</td></tr></table>";

function ShAlt(sText, nTableW, nVOffset, nHOffset)
{
	alImg( (atText1 + (nTableW > 0 ? (" width=" + nTableW) : "") + 
			atText2 + sText + atText3), 
			(nHOffset == 'undefined' || isNaN(nHOffset) ? 
			-10 : nHOffset),
			(nVOffset == 'undefined' || isNaN(nVOffset) ? 
			-20 : nVOffset) );
}

function HdAlt()
{
	atHideAltText();
}


function CenterLayer (layer,width,height,target) {
	leftLayer = (target.body.clientWidth - width)/2;
	leftLayerABS = (target.body.clientHeight - height)/2;

	topLayer=target.body.scrollTop;
	
	newTop=topLayer+leftLayerABS;
	if (newTop < 0)
		newTop=0;

	target.getElementById(layer).style.left = leftLayer;
	target.getElementById(layer).style.top=topLayer+leftLayerABS;
} 

var OldActiveLink='';

function SwitchMenuLink (sLink) {


	obj=MM_findObj(OldActiveLink);
	if (obj) {
        obj.style.textDecorationNone=false;
        obj.style.color='#000000';
        obj.style.cursor='pointer';
	}

	obj=MM_findObj(sLink);
	if (obj) {
        obj.style.textDecorationNone=true;
        obj.style.color='#A0A0A0';
        obj.style.cursor='normal';
        OldActiveLink=sLink;
	}
}

function SetCopyPosition () {

	nY1=1400;
	
	obj=MM_findObj('needtbl1');
	nY2=(findPosY(obj)+20);
	
	obj=MM_findObj('needtbl2');
	nY3=findPosY(obj);
	
	nY=0;

	if ((nY3  >=  nY1) && (nY3 >=  nY2))
		nY=nY3;
		
	if ((nY2  >=  nY1) && (nY2 >=  nY3))
		nY=nY2;
		
	if ((nY1 >=  nY2) && (nY1 >=  nY3))
		nY=nY1;
	
	obj=MM_findObj('copy');
	if (obj) {
		obj.style.top=nY;
		obj.style.visibility='visible';
	}
}