/* javascript supplied by Euro Business Enterprises Ltd - ebewebdesign.co.uk */

function loadContent(url,id,append)
{
  var xmlHttp;
  try
  {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }

  catch (e)
  {
    // Internet Explorer
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }

    catch (e)
    {
      try
      {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }

      catch (e)
      {
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }

  xmlHttp.onreadystatechange=function()
  {
    if(xmlHttp.readyState==4)
    {
      if(append==1)
      {
        var foo = document.getElementById(id);
        var option = document.createElement('div');
        option.innerHTML = xmlHttp.responseText;
        foo.appendChild(option); 

      }
      else
      {
        document.getElementById(id).innerHTML=xmlHttp.responseText;
      }
    }
  }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function loadImage(url,id)
{
  document.getElementById(id).src=url;
}

function selectFile(id,url,id_to_update) // pass back URL to item id
{
  // cms text area file selector
  if(document.getElementById('lf_url'+idTa))
    document.getElementById('lf_url'+idTa).value = url;

  if(document.getElementById('if_url'+idTa))
    document.getElementById('if_url'+idTa).value = url;

  // other field file selector
  if(document.getElementById(id_to_update))
    document.getElementById(id_to_update).value = url;

  document.getElementById(id).style.visibility = "hidden";
  document.getElementById(id).style.display = "none";
}

function checkit(url)
{
  var ok=confirm('Are you sure you want to delete this item?');
  if(ok)
  {
    window.location = url;
  }
}

function checkAjax()
{
  var ok=confirm('Are you sure you want to delete this item?');
  if(ok)
  {
    return true;
  }
  else
  {
    return false;
  }
}

function deletefile(url,id)
{
  var ok=confirm('Are you sure you want to delete this item?');
  if(ok)
  {
    loadContent(url,id);
  }
}


function loadText(newtext,id)
{
  document.getElementById(id).value = newtext;
}


function go(url)
{
    window.location = url;
}

function goOut(url)
{
    window.open(url,'_blank');
}

function setFocus(id)
{
  var elem = document.getElementById( id );
    if ( elem ) 
    {
      elem.focus();    // May throw "Permission denied" (uncatchable)
    }
}

function submitForm(formname)
{
  document.getElementById(formname).submit();
}


function submitFormByButton(button)
{
   document.getElementById(button).click();
}






function checkSubmit(url,checkid)
{
if(document.getElementById(checkid).checked)
{
  var ok=confirm('Are you sure you want to send the newsletter?');
  if(ok)
  {
    return;
  }
  else
  {
    window.location = url;
    return false;
  }
}

}






/* extremely simple drop-down menu created by EBE */
/* this mocks the arrogant developers who use complex methods to create something simple */
function submenuOn(theDiv) 
{
  var parentDiv = theDiv.substr(0,theDiv.length - 4);

  var leftMargin = document.getElementById(parentDiv).offsetLeft;

  document.getElementById(theDiv).style.marginLeft = leftMargin+"px";

  if(typeof(currentdiv) != 'undefined')
  {
    var previouselem = document.getElementById(currentdiv);
    previouselem.style.visibility = "hidden";
  }

  if(typeof(currenttimeout) != 'undefined')
  {
    clearTimeout(currenttimeout);
  }

  var elem = document.getElementById(theDiv);
  elem.style.visibility = "visible";
}

function submenuOff(theDiv) 
{
  var elem = document.getElementById(theDiv);
  elem.style.visibility = "hidden";
}

function submenuOffTimer(theDiv) 
{
  currenttimeout = setTimeout("submenuOff('"+theDiv+"')", 500); // after 1 sec
  currentdiv = theDiv;
}




function showDiv(theDiv)
{
  var elem = document.getElementById(theDiv);
  elem.style.visibility = "visible";
  return;
}

function hideDiv(theDiv)
{
  var elem = document.getElementById(theDiv);
  elem.style.visibility = "hidden";
  return;
}


function showHide(id,on_off)
{
  // takes id of calling object, whether it is on or off, and also id of object to focus on when set to on
/*
  if(typeof(on_off) != 'undefined')
  {
    if (on_off == "off") 
    {
      d.style.visibility = "hidden";
    }
  }
  else
  {
    d.style.visibility = "visible";
  }
*/
  var d = document.getElementById(id);

  if (d.style.visibility == "visible") 
  {
    d.style.visibility="hidden"; d.style.display="none"; 
    d.style.height="1px";
  }
  else
  {
    d.style.visibility="visible"; d.style.display='';
    d.style.height="auto";
  }
}
































function PrintContent(ctrl) 
{ 
  var dataToPrint = document.getElementById(ctrl).innerHTML; 
   
  //var winprint=window.open("","","toolbar=yes,location=no,directories=yes,menubar=no,scrollbars=yes,width=560,height=400,left=100,top=25"); 
  var winprint=window.open("","","toolbar=yes,location=no,directories=yes,menubar=no,scrollbars=yes,width=560,height=400,left=100,top=25"); 
  winprint.document.open(); 
  winprint.document.write('<html><link href=scripts/print.css rel=stylesheet><body>'); 
  winprint.document.write(dataToPrint);          
  winprint.document.write('</body></html>'); 
  winprint.document.close(); 
  winprint.focus(); 

  winprint.print();
  winprint.close();
}



    var bouncyTime = 2                  //seconds - depends on computer some slower computer will take longer
    var stickyness = 2;                 //if we are using the easy method, this restricts bouncyness
    var useRealDHO = false              //use realistic dynamic harmonic oscillations. This can be slower.
        //these variables are used with realistic DHO. this is overkill for most webapps. 
        var mass = 1;                   //mass of object affects momentum
        var dampingConst =3;            //think of this as friction
        var frequency = 3;              //cycles per second

    var scrollerId = 'bounceblock'      //id of the div to scroll
    var startpos = null;                  //keep at least this far from the top
    var waitTime = '0'               //Time to wait before starting animation (milliseconds)

    var startPoint;                 
    var endPoint; 
    var intval 
    var timeout    
    var t = 0;

 

    //helper function
    function byId(id){
        return document.getElementById(id);
    }

    //trim 'px' helper function
  function trimPx(strg){
        strip=/[px,pt,em]/gi;
        strg?null:strg="0px";
        strg.replace(strip,'');
        return parseInt(strg);
    }

    //kick off our animation
    function init(endpos){
        //if we have an animation already in progress, cancel it 
        (intval?window.clearInterval(intval):null)
        //reset our time to zero
        t = 0;
        //get the starting point by finding the top of our div
        startPoint = startpos;
        endPoint = endpos+startpos;
        intval = window.setInterval("oscillate()",10);
    }

    function oscillate(){ 
        //if we are at the end of our time //then stop the animation//else, increment the time for our equation
        (t == 1000?window.clearInterval(intval):t += 10/bouncyTime)
        //scale it for our equation
        ts = t/100;
        //if we are using real Damped harmonic oscillation
        if (useRealDHO){
            od = dampingConst/(2*mass);
            oprime = Math.sqrt(frequency*frequency - od*od);
            moveto = (startPoint-endPoint) * Math.pow(Math.E,-ts*od) * Math.cos(2*Math.PI+(ts*oprime)) + endPoint ;   
        }else{
            //else, do the quick method
            moveto =  (startPoint-endPoint) * Math.pow(Math.E,-ts) * Math.cos(2*Math.PI*(ts/stickyness)) + endPoint;
        }   
        //keep it from going up too far
        //moveto < 0 ? moveto = 0 : null; // DISABLED!
        byId(scrollerId).style.top = Math.round(moveto) + "px";
    }


    //helper function to return scroll location
    function f_filterResults(n_win, n_docel, n_body) {
      var n_result = n_win ? n_win : 0;
      if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
      return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
    }

    function bounce(startpos,endpos,id,frame) {
      this.startpos = startpos;
      this.scrollerId = id+frame;

      if(frame>1)
      {
        oldframe=frame-1;
        fade(id+oldframe,1000,true);
      }

      if(document.getElementById(id+frame) == null)
      {
        frame=1;
        this.scrollerId = id+frame;       
      }

      frame=frame+1;

      startpos ? null : startpos = document.getElementById(scrollerId).top * -1 + 30;  
      (timeout?window.clearTimeout(timeout):null);
      timeout = window.setTimeout("init("+endpos+")",waitTime);
      
      //setTimeout("bounce(-220,250,'"+id+"',"+frame+");", 9000);
      

      var delay = function() { bounce(-220,250,id,frame); };
      setTimeout(delay, 9000);
      
      
    };





function fade(eid,fadetime,reset)
{
  var element = document.getElementById(eid);
  if(element == null)
    return;
   
  if(element.FadeState == null)
  {
    if(element.style.opacity == null
        || element.style.opacity == ''
        || element.style.opacity == '1')
    {
      element.FadeState = 2;
    }
    else
    {
      element.FadeState = -2;
    }
  }
   
  if(element.FadeState == 1 || element.FadeState == -1)
  {
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = fadetime - element.FadeTimeLeft;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = fadetime;
    //setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "',"+fadetime+","+reset+")", 33);
    
    foo = new Date().getTime();
    var delay = function() { animateFade(foo,eid,fadetime,reset); };
    setTimeout(delay, 33);
    

  }  
}

function animateFade(lastTick, eid, fadetime, reset)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
 
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = '
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    
    /* reset element data */
    if(reset)
    {
      document.getElementById(eid).style.top = '-200px';
      document.getElementById(eid).style.filter = 'alpha(opacity=100)';
      document.getElementById(eid).style.opacity = '1';
      document.getElementById(eid).FadeState = 2;
      document.getElementById(eid).FadeTimeLeft = fadetime;
    }
    
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/fadetime;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
 
  //setTimeout("animateFade(" + curTick + ",'" + eid + "',"+fadetime+","+reset+")", 33);
  
  
  var delay = function() { animateFade(curTick,eid,fadetime,reset); };
  setTimeout(delay, 33);
  
}








/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX=-5 //Customize x offset of tooltip
var offsetfromcursorXRight=-30 //Customize x offset of tooltip (ebe)
var offsetfromcursorY=15 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="images/arrow2.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
pointerobj.style.left=curX+offsetfromcursorXRight+"px"
//nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

//document.onmousemove=positiontip

if ( typeof window.addEventListener != "undefined" )
document.addEventListener( "mousemove", positiontip, false );
else if ( typeof window.attachEvent != "undefined" )
document.attachEvent( "onmousemove", positiontip );
else {
if ( document.onmousemove != null ) {
var oldOnmousemove = document.onmousemove;
document.onmousemove = function ( e ) {
oldOnmousemove( e );
positiontip(e);
};
}
else
document.onmousemove = positiontip;
}










