var IE=(document.all),  NS=((navigator.appName=='Netscape')&&document.layers), NS6=(navigator.appName=='Netscape')&&document.getElementsByTagName;

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

/*
function si() {
  var i,j=0,x,a=si.arguments; for(i=0;i<a.length;i++)
   //if ((x=MM_findObj(a[i]))!=null){if(!x.oSrc) x.oSrc=x.src; x.src=x.src.replace(/_(.)\./g, "_$1o.");}
   if ((x=MM_findObj(a[i]))!=null){if(!x.oSrc) x.oSrc=x.src; x.src=x.src.replace(/_u\./g, "_d\.");}
}
function sir() {
  var i,x,a=sir.arguments; for(i=0;i<a.length&&(x=MM_findObj(a[i]))&&x.oSrc;i++) x.src=x.oSrc;
}
*/

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function move_layer_to(obj, newLeft, newTop){
  if (NS) {obj.left = newLeft; obj.top = newTop;}
  else if(NS6) {obj.style.left = newLeft; obj.style.top = newTop;}
  else {obj.style.pixelLeft = newLeft; obj.style.pixelTop = newTop;}
}

function move_layer_to_x(obj, newLeft){
  if (NS) {obj.left = newLeft; }
  else if(NS6) {obj.style.left = newLeft;}
  else {obj.style.pixelLeft = newLeft; }
}

function move_layer_to_y(obj, newTop){
  if (NS) {obj.top = newTop;}
  else if(NS6) {obj.style.top = newTop;}
  else { obj.style.pixelTop = newTop;}
}

function move_layer_by(obj, newLeft, newTop){
  if (NS) {obj.left += newLeft; obj.top += newTop;}
  else if(NS6) {obj.style.left = parseInt(obj.style.left) + newLeft; obj.style.top = parseInt(obj.style.top) + newTop;}
  else {obj.style.pixelLeft += newLeft; obj.style.pixelTop += newTop;}
}

function get_absolute_left(b){
	if(NS) return b.pageX;

	var T = b.offsetLeft;
	if(NS6)
	while ((b = b.parentNode) != null )
		if(b.style && b.style.position && b.offsetLeft) T += b.offsetLeft;

	if(IE)
	while ((b = b.parentElement) != null )
		if(b.style && b.style.position && b.offsetLeft) T += b.offsetLeft;

	return T;
}

function get_absolute_top(b){
	if(NS) return b.pageY;

	var T = b.offsetTop;
	if(NS6)
	while ((b = b.parentNode) != null )
		if(b.style && b.style.position && b.offsetTop) T += b.offsetTop;

	if(IE)
	while ((b = b.parentElement) != null )
		if(b.style && b.style.position && b.offsetTop) T += b.offsetTop;

	return T;
}

function get_relative_top(b){
	if(NS) return b.top;
	//if(IE) return b.style.pixelTop;
	if(IE) return b.offsetTop;
	if(b.style.position=='absolute') return b.offsetTop;
	if(!b.style.top)  return 0;
	if(b.style.top.search('px')!=-1) return parseInt(b.style.top);
	return b.offsetTop;
}

function get_relative_left(b){
	if(NS) return b.left;
	//if(IE) return b.style.pixelLeft;
	if(IE) return b.offsetLeft;
	if(b.style.position=='absolute') return b.offsetLeft;
	if(!b.style.left)  return 0;
	if(b.style.left.search('px')!=-1) return parseInt(b.style.left);
	return b.offsetLeft;
}






function get_absolute_width(b){  // ����� ���������� �������� ����� �� � �������� �� ������ ��� �������� ����� � ��������.
	if(IE || NS6) return b.scrollWidth;
	if(NS) return b.document.width;
}

function get_absolute_height(b){  // ����� ���������� �������� ����� �� � �������� �� ������ ��� �������� ����� � ��������.
	if(IE) return Math.max(b.clientHeight, b.scrollHeight);
	if(NS6) return b.scrollHeight;
	if(NS) return b.document.height;
}

function get_client_width(b){//����� ���������� �� �������� ����.
	if(NS) return b.clip.width;
	if(IE || NS6) {
		var clip = get_clip_rec(b);
		return (clip.right - clip.left);
	}
}

function get_client_height(b){//����� ���������� �� �������� ����.
	if(NS) return b.clip.height;
	if(IE || NS6) {
		var clip = get_clip_rec(b);
		return (clip.bottom - clip.top);
	}
}


function get_clip_rec(b){
	var clip = {top:0, left:0, bottom:0, right:0}
	if(NS){
		clip.top = b.clip.top;
		clip.left = b.clip.left;
		clip.bottom = b.clip.bottom;
		clip.right = b.clip.right;
	} else {
		var s = b.style.clip;
		if(s && b.style.position=="absolute"){
			s = s.slice(5);
			s = s.split(" ", 4);

			clip.top = parseInt(s[0]);
			clip.left = parseInt(s[3]);
			clip.bottom = parseInt(s[2]);
			clip.right = parseInt(s[1]);
		} else {
			clip.top = 0;
			clip.left = 0;
			clip.bottom = get_absolute_height(b);
			clip.right = get_absolute_width(b);
		}
	}
	return clip;
}

function set_clip_rec(b, clip){
	if (NS) {
		b.clip.top = clip.top;
		b.clip.left = clip.left;
		b.clip.bottom = clip.bottom;
		b.clip.right = clip.right;
	} else {
  	b.style.clip ='rect(' + clip.top + ' ' + clip.right + ' ' + clip.bottom + ' ' + clip.left + ')';
  }
}



function prevent_clickondrag(e){
	var srcElement = (NS6||NS) ? e.target : event.srcElement;
	srcElement.onclick = null;
	if(NS6) srcElement.removeEventListener("click", prevent_clickondrag, false);
	return false;
}

function MM_dragLayer(objName,x,hL,hT,hW,hH,toFront,dropBack,cU,cD,cL,cR,targL,targT,tol,dropJS,et,dragJS) { //v3.0
  //Copyright 1998 Macromedia, Inc. All rights reserved.
  var i,j,aLayer,retVal,curDrag=null, curLeft, curTop;
  if (!document.all && !document.layers && !document.getElementsByTagName) return false;
  retVal = true; if(!NS &&!NS6 && event) event.returnValue = true;
  if (MM_dragLayer.arguments.length > 1) {
    curDrag = MM_findObj(objName); if (!curDrag) return false;
    if (!document.allLayers) { document.allLayers = new Array();
      with (document) if (NS) { for (i=0; i<layers.length; i++) allLayers[i]=layers[i];
        for (i=0; i<allLayers.length; i++) if (allLayers[i].document && allLayers[i].document.layers)
          with (allLayers[i].document) for (j=0; j<layers.length; j++) allLayers[allLayers.length]=layers[j];
      } else if(IE) {for (i=0;i<all.length;i++) if (all[i].style&&all[i].style.position) allLayers[allLayers.length]=all[i];}
      else {var all=getElementsByTagName("div"); for (i=0;i<all.length;i++) if (all[i].style&&all[i].style.position) allLayers[allLayers.length]=all[i];
     	 all=getElementsByTagName("span"); for (i=0;i<all.length;i++) if (all[i].style&&all[i].style.position) allLayers[allLayers.length]=all[i];
      }
    }

    curDrag.MM_dragOk=true; curDrag.MM_targL=targL; curDrag.MM_targT=targT;
    curDrag.MM_tol=Math.pow(tol,2); curDrag.MM_hLeft=hL; curDrag.MM_hTop=hT;
    curDrag.MM_hWidth=hW; curDrag.MM_hHeight=hH; curDrag.MM_toFront=toFront;
    curDrag.MM_dropBack=dropBack; curDrag.MM_dropJS=dropJS;
    curDrag.MM_everyTime=et; curDrag.MM_dragJS=dragJS;
    curDrag.MM_oldZ = (NS)?curDrag.zIndex:curDrag.style.zIndex;
    curLeft= get_relative_left(curDrag); curDrag.MM_startL = curLeft;
    curTop = get_relative_top(curDrag); curDrag.MM_startT = curTop;
    curDrag.MM_bL=(cL<0)?null:curLeft-cL; curDrag.MM_bT=(cU<0)?null:curTop -cU;
    curDrag.MM_bR=(cR<0)?null:curLeft+cR; curDrag.MM_bB=(cD<0)?null:curTop +cD;
    curDrag.MM_LEFTRIGHT=0; curDrag.MM_UPDOWN=0; curDrag.MM_SNAPPED=false; //use in your JS!
    document.onmousedown = MM_dragLayer; document.onmouseup = MM_dragLayer;
    if (NS) document.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
    if(NS6){
    	document.addEventListener("mousedown", MM_dragLayer, false);
    	document.addEventListener("mouseup", MM_dragLayer, false);
    }
  } else {
    var theEvent = ((NS||NS6)?objName.type:event.type);
		if(NS || NS6) event = objName;
    if (theEvent == 'mousedown') {
      var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft;
      var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop;

      var maxDragZ=null; document.MM_maxZ = 0;
      for (i=0; i<document.allLayers.length; i++) { aLayer = document.allLayers[i];
        var aLayerZ = (NS)?aLayer.zIndex:aLayer.style.zIndex;
        if (aLayerZ > document.MM_maxZ) document.MM_maxZ = aLayerZ;
        var isVisible = (((NS)?aLayer.visibility:aLayer.style.visibility).indexOf('hid') == -1);
        if (aLayer.MM_dragOk != null && isVisible) with (aLayer) {
          var tmpX=mouseX-(get_absolute_left(aLayer)+MM_hLeft);
          var tmpY=mouseY-(get_absolute_top(aLayer)+MM_hTop);

          var tmpW = MM_hWidth;  if (tmpW <= 0) tmpW += ((NS)?clip.width :offsetWidth);
          var tmpH = MM_hHeight; if (tmpH <= 0) tmpH += ((NS)?clip.height:offsetHeight);

          if ((0 <= tmpX && tmpX < tmpW && 0 <= tmpY && tmpY < tmpH) && (maxDragZ == null
              || maxDragZ <= aLayerZ)) { curDrag = aLayer; maxDragZ = aLayerZ; } } }
      if (curDrag) {

        document.onmousemove = MM_dragLayer; if (NS) document.captureEvents(Event.MOUSEMOVE);
        if(NS6) document.addEventListener("mousemove", MM_dragLayer, false);
        curLeft = get_relative_left(curDrag);
        curTop = get_relative_top(curDrag);

        MM_oldX = mouseX - curLeft; MM_oldY = mouseY - curTop;
        document.MM_curDrag = curDrag;  curDrag.MM_SNAPPED=false;
        if(curDrag.MM_toFront) {
          eval('curDrag.'+((NS)?'':'style.')+'zIndex=document.MM_maxZ+1');
          if (!curDrag.MM_dropBack) document.MM_maxZ++; }

				curDrag.A = false;
				var srcElement = (NS6||NS) ? event.target : event.srcElement;

				if(!NS && srcElement && (srcElement.nodeName!="A")){
					while ((srcElement = srcElement.parentNode) != null ) if(srcElement.nodeName=="A") break;
				}
				if(srcElement && (srcElement.nodeName=="A")){
					curDrag.A = srcElement;

					curDrag.A.onclick=prevent_clickondrag;
					if(NS6) curDrag.A.addEventListener("click", prevent_clickondrag, false);
				}
				curDrag.moved = false;
        retVal = false; if(!NS) event.returnValue = false;
 				if(NS && srcElement) {curDrag.A = srcElement; retVal = true;}
    } } else if (theEvent == 'mousemove') {

      if (document.MM_curDrag) with (document.MM_curDrag) {
      	moved = true;
        var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft;
        var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop;

        newLeft = mouseX-MM_oldX; newTop  = mouseY-MM_oldY;
        if (MM_bL!=null) newLeft = Math.max(newLeft,MM_bL);
        if (MM_bR!=null) newLeft = Math.min(newLeft,MM_bR);
        if (MM_bT!=null) newTop  = Math.max(newTop ,MM_bT);
        if (MM_bB!=null) newTop  = Math.min(newTop ,MM_bB);
        MM_LEFTRIGHT = newLeft-MM_startL; MM_UPDOWN = newTop-MM_startT;

        if (NS) {left = newLeft; top = newTop;}
        //else {style.pixelLeft = newLeft; style.pixelTop = newTop;}
        else {style.left = newLeft; style.top = newTop;}
        if (MM_dragJS) eval(MM_dragJS);
        retVal = false; if(!NS) event.returnValue = false;
    } } else if (theEvent == 'mouseup') {
      document.onmousemove = null;
      if (NS6) document.removeEventListener("mousemove",MM_dragLayer,false);
      if (NS) document.releaseEvents(Event.MOUSEMOVE);
      if (NS) document.captureEvents(Event.MOUSEDOWN); //for mac NS
      if (document.MM_curDrag) with (document.MM_curDrag) {
      	if(!moved && A){
      	  A.onclick = null;
      	  A.removeEventListener("click", prevent_clickondrag, false);
      	}
        if (typeof MM_targL =='number' && typeof MM_targT == 'number' &&
            (Math.pow(MM_targL-((NS)?left:style.pixelLeft),2)+
             Math.pow(MM_targT-((NS)?top:style.pixelTop),2))<=MM_tol) {
          if (NS) {left = MM_targL; top = MM_targT;}
          else {style.pixelLeft = MM_targL; style.pixelTop = MM_targT;}
          MM_SNAPPED = true; MM_LEFTRIGHT = MM_startL-MM_targL; MM_UPDOWN = MM_startT-MM_targT; }
        if (MM_everyTime || MM_SNAPPED) eval(MM_dropJS);
        if(MM_dropBack) {if (NS) zIndex = MM_oldZ; else style.zIndex = MM_oldZ;}
        retVal = false; if(!NS) event.returnValue = false;
        if(NS && A) retVal = true;
      }
      document.MM_curDrag = null;
    }
    if (NS) document.routeEvent(objName);
  } return retVal;
}



var showTime = Array();


function addbookmark(){
if (document.all)
	window.external.AddFavorite(location, document.title)
}

function showsubmenu(name){
	//dumpMsg('In '+name);
	window.clearTimeout(showTime[name]);
	showTime[name] = false;

	var o = document.getElementById('submenu_'+name);
	if(o)
		o.style.visibility = 'visible';
}

function hidesubmenu(name){
	//dumpMsg('Out '+name);
	if(showTime[name]) return;
		showTime[name] = window.setTimeout("hidesubmenu2('"+name+"')", 200);
}

function hidesubmenu2(name){
	var o = document.getElementById('submenu_'+name);
	if(o)
		o.style.visibility = 'hidden';
}

function dumpMsg(msg){
	var o = document.getElementById('debugConsole');
	o.value =  msg + "\n" + o.value;
}

function getParentFormElement(elem) {
  form_obj = elem;
  while (form_obj.tagName!='FORM') {
    form_obj = form_obj.parentNode;
    if (!form_obj) {
      alert('Form not found! Please put the list control in a form!'); return 0;
    }
  }
  return form_obj;
}

function add_to_favourite() {
	if (window.sidebar) {
		window.sidebar.addPanel(document.title,self.location,'');
	} 
	else if (window.external) {
		window.external.AddFavorite(self.location,document.title);
	} 
	else if (window.opera) {
	     var e = document.createElement('a');
	     e.setAttribute('href',self.location);
	     e.setAttribute('title',document.title);
	     e.setAttribute('rel','sidebar');
	     e.click();
	}
}	
