
//@@*******************
//@@ common scripts
//@@ JIA 28/11/06
//@@*******************


//@@*******************
//@@ onload function
//@@ detects browser type
//@@ JIA 28/11/06
//@@*******************

//@@ global broswer
var gsBrowser = "";

//@@ global menu
var oMenu = null;

//@@ global image ref
var mlngImg = 0;

//@@ global solution ref
var mlngRef = 0;

//@@ page
var msPage = "";

window.onload = function() {

   //@@ look for mozilla
   if ((typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') == true)
      gsBrowser = "mz"
   else
      gsBrowser = "ie"

   //@@ include header
   clientSideInclude('incHeader', 'inc/header.inc');

   //@@ include footer media
   clientSideInclude('incFooterMedia', 'inc/footer_media.inc');

   //@@ include footer recording
   clientSideInclude('incFooterRecording', 'inc/footer_recording.inc');

   //@@ get current page
   msPage = window.location.href;
   msPage = msPage.substring(msPage.lastIndexOf("/")+1,msPage.length);
   msPage = msPage.substring(0,msPage.indexOf("."));

   //@@ set page title
   if (document.getElementById("tdPageTitle") != null)
      {
       //@@ trap index page
       if (msPage != "index" && msPage != "")
          {
           document.getElementById("tdPageTitle").innerHTML = msPage.replace(/_/g," ");
           document.title = "dare music - " + msPage.replace(/_/g," ");
          }
      }

   //@@ check for top link
   if (document.getElementById("toplink" + msPage) != null)
      document.getElementById("toplink" + msPage).className = document.getElementById("toplink" + msPage).className + "Active";

   //@@ check for other onload events
   if (msPage == "location")
      {
       //@@ build google map
       m_map();
      }
   if (msPage == "news")
      {
       //@@ build news page
       m_news_load();
      }
   if (msPage == "solution")
      {
       //@@ build solution page
       m_solution_load();
      }
   if (msPage == "tips")
      {
       //@@ build solution page
       m_tip_load();
      }

}

//@@ controls style for onmouseover/out events

function m_btn_move(ev,oCon) {

   //@@ check for window event
   if (!ev) 
      ev = window.event;

   //@@ sets class name
   if (ev.type == "mouseover")
      {
       //@@ check for link
       if (document.getElementById("toplink" + msPage) != null)
          {
           if (document.getElementById("toplink" + msPage).id == oCon.id)
              oCon.className = oCon.className.substring(0,oCon.className.indexOf("Active")) + "Over";
           else
              oCon.className = oCon.className + "Over";
          }
       else
          oCon.className = oCon.className + "Over";
      }
   else 
      {
       if (document.getElementById("toplink" + msPage) != null)
          {
           //@@ check for link
           if (document.getElementById("toplink" + msPage).id == oCon.id)
              oCon.className = oCon.className.substring(0,oCon.className.indexOf("Over")) + "Active";
           else
              oCon.className= oCon.className.substring(0,oCon.className.indexOf("Over"));
          }
       else
          oCon.className= oCon.className.substring(0,oCon.className.indexOf("Over"));
      }

}

function findPos(obj) {

   //@@ finds object position
   var curleft = curtop = 0;

   //@@ calculate
   if (obj.offsetParent) 
      {
       curleft = obj.offsetLeft;
       curtop = obj.offsetTop;

       while (obj = obj.offsetParent) 
          {
	   curleft += obj.offsetLeft;
	   curtop += obj.offsetTop;
	  }
      }

   return [curleft,curtop];
}

function m_img_display(oCon) {

   //@@ this displays the selected image as a full screen photo

   //@@ set width and height
   var iW = 800;
   var iH = 500;

   //@@ work out left and top
   //@@ for centre screen
   var iL = (window.screen.availWidth/2) - (iW/2);
   var iT = (window.screen.availHeight/2) - (iH/2);
   
   //@@ built positon
   var sPos = "left=" + iL + ",top=" + iT + ",width=" + iW + ",height=" + iH;

   //@@ open window
   var oWin = window.open("gallery.htm","winGallery",sPos + ",directories=no,location=no,menubar=no,resizable=yes,scrollbars=no,status=no,titlebar=no,toolbar=no");

   //@@ get correct image
   //@@ if from menu bar then select
   //@@ first image
   if (oCon == null)
      var lngImg = 0;
   else
      {
       //@@ get gallery xml root
       var xmlRoot = m_xml("xml/gallery.xml");

       //@@ get node list of all gallerys
       var xmlNodeList = xmlRoot.getElementsByTagName("gallery");

       //@@ loop round gallerys looking for match
       for (var i=0; i<xmlNodeList.length; i++)
          {
           //@@ look for match
           if (xmlNodeList[i].getElementsByTagName("src")[0].childNodes[0].nodeValue == oCon.src.substring(oCon.src.lastIndexOf("/")+1,oCon.src.length))
              var lngImg = xmlNodeList[i].getAttributeNode("pos").nodeValue - 1;
          }
      }
 
   //@@ set global image id
   mlngImg = lngImg;

}


function m_solution_click(lngRef) {

   //@@ this displays the selected solution

   //@@ set width and height
   var iW = 700;
   var iH = 400;

   //@@ work out left and top
   //@@ for centre screen
   var iL = (window.screen.availWidth/2) - (iW/2);
   var iT = (window.screen.availHeight/2) - (iH/2);
   
   //@@ build positon
   var sPos = "left=" + iL + ",top=" + iT + ",width=" + iW + ",height=" + iH;

   //@@ open window
   var oWin = window.open("solution.htm","winSolution",sPos + ",directories=no,location=no,menubar=no,resizable=yes,scrollbars=no,status=no,titlebar=no,toolbar=no");
 
   //@@ set global ref id
   mlngRef = lngRef-1;

}

function m_window_open(sPage, iH, iW) {

   //@@ this displays the selected window

   //@@ work out left and top
   //@@ for centre screen
   var iL = (window.screen.availWidth/2) - (iW/2);
   var iT = (window.screen.availHeight/2) - (iH/2);
   
   //@@ build positon
   var sPos = "left=" + iL + ",top=" + iT + ",width=" + iW + ",height=" + iH;

   //@@ open window
   var oWin = window.open(sPage,"winUnknown",sPos + ",directories=no,location=no,menubar=no,resizable=yes,scrollbars=no,status=no,titlebar=no,toolbar=no");

}

function m_copyright() {

   //@@ this displays the selected window

   var iH = 500;
   var iW = 800;
   var sPage = "copyright.htm";

   //@@ work out left and top
   //@@ for centre screen
   var iL = (window.screen.availWidth/2) - (iW/2);
   var iT = (window.screen.availHeight/2) - (iH/2);
   
   //@@ build positon
   var sPos = "left=" + iL + ",top=" + iT + ",width=" + iW + ",height=" + iH;

   //@@ open window
   var oWin = window.open(sPage,"winCopyright",sPos + ",directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no");

}


//@@ include common html 

function clientSideInclude(id, url) {
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
 var element = document.getElementById(id);
 if (!element) {
  //alert("Bad id " + id + 
  // "passed to clientSideInclude." +
  // "You need a div or span element " +
  // "with this id in your page.");
  return;
 }
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('GET', url, false);
    req.send(null);
    element.innerHTML = req.responseText;
  } else {
    element.innerHTML =
   "Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.";
  }
}

function m_xml(urlPath) {

   //@@ this returns an xmlRoot element
   //@@ to the passed in file

   //@@ check browser
   if (gsBrowser == "ie")
      {
       //@@ load up the gallery xml file
       var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
       xmlDoc.async = false;
       xmlDoc.resolveExternals = false;
       xmlDoc.load(urlPath);
      }
   else
      {
       var xmlDoc = document.implementation.createDocument("","",null);
       xmlDoc.async = false;
       xmlDoc.resolveExternals = false;
       xmlDoc.load(urlPath);
      }

   //@@ set root element
   var xmlRoot = xmlDoc.documentElement;

   //@@ return the root
   return(xmlDoc);

}

function m_player(sSample, sTitle) {

   //@@ this displays the player window

   var iH = 170;
   var iW = 320;
   var sPage = "player.htm?sample=" + sSample + "&title=" + sTitle;

   //@@ work out left and top
   //@@ for centre screen
   var iL = (window.screen.availWidth/2) - (iW/2);
   var iT = (window.screen.availHeight/2) - (iH/2);
   
   //@@ build positon
   var sPos = "left=" + iL + ",top=" + iT + ",width=" + iW + ",height=" + iH;

   //@@ open window
   var oWin = window.open(sPage,"winPlayer",sPos + ",directories=no,location=no,menubar=no,resizable=yes,scrollbars=no,status=no,titlebar=no,toolbar=no");

}