/* 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 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";
  elem.style.display = "";
  return;
}

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

function uncheck(theDiv)
{
  var elem = document.getElementById(theDiv);
  elem.checked = false;
  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 navMenu(id,maxid)
{
  for(i=0; i < maxid; i++)
  {
    sm = 'sub_menu_'+i;

    d = document.getElementById(sm);

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

    mm = 'menu_'+i;
    d = document.getElementById(mm);

    if(d)
    {
      d.className="menu-item";
    }

    if(sm == id)
    {
      d.className="menu-item-on";
    }

  }

  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";
    //d.className="menu-item-on";
  }
}



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();
}


