/* 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 setFocus(id)
{
  var elem = document.getElementById( id );
    if ( elem ) 
    {
      elem.focus();    // May throw "Permission denied" (uncatchable)
    }
}

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




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 lightbuttonchange(id)
{
  var elem = document.getElementById(id);

  if(elem.className == "bl")
  {
    elem.className = "bl_on";
    elem.style.cursor = 'pointer';
  }
  else
  {
    elem.className = "bl";
  }
}

function lightbutton2change(id)
{
  var elem = document.getElementById(id);

  if(elem.className == "bl_side_bg")
  {
    elem.className = "bl_on";
    elem.style.cursor = 'pointer';
  }
  else
  {
    elem.className = "bl_side_bg";
  }
}

function lightbuttonmainchange(id)
{
  var elem = document.getElementById(id);

  if(elem.className == "bl_main")
  {
    elem.className = "bl_main_on";
    elem.style.cursor = 'pointer';
  }
  else
  {
    elem.className = "bl_main";
  }
}

function checkEventFields(item_id)
{
  var a = document.getElementById('event_sign_up_dinghy_type_'+item_id);
  var b = document.getElementById('event_sign_up_sail_no_'+item_id);
  var c = document.getElementById('event_sign_up_py_'+item_id);
  var d = document.getElementById('event_sign_up_helm_name_'+item_id);
  var e = document.getElementById('event_sign_up_helm_address_'+item_id);
  var f = document.getElementById('event_sign_up_risk_'+item_id);
  var g = document.getElementById('event_sign_up_under_18_'+item_id);

  var h = document.getElementById('event_sign_up_emergency_contact_name_'+item_id);
  var i = document.getElementById('event_sign_up_emergency_contact_telephone_'+item_id);

  if(!a.value.length || !b.value.length || !c.value.length || !d.value.length || !e.value.length || !f.checked || !g.checked || !h.value.length || !i.value.length)
  {
    alert('Please fill in all required fields.');
    return false;
  }
  else
  {
    return true;
  }

}


/***********************************************
* 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;
}