//CML Shared scripts
//
//

var fname="main";     //MAIN CONTENT AREA FRAME **NAME**

// loadSearchRefs - like loadRefs, but calls the search page in the left hand pane with supplied parameters
// loadSearchRefs & goSetHeight normally called together by the "loadSearchPage" function
function loadSearchRefs() {
var d=document.location.search;

          //
          // Bit of explanation called for here...
          // This page has 2 frames - "Main" (right frame) & "Contents" (left)
          //   and can be called with 2 parameter sets, separated by "?" - for example...

          //   i.e http://www.cmlmicro.com/Products/Index.asp?http://www.cmlmicro.com/Products/land/WDland.htm& 
          //http://www.cmlmicro.com/search/OVSearch.asp

          if (d.indexOf('&')== -1) {
            var contents = "";
            var main = d.substring(d.lastIndexOf('?')+1,d.length);
          } else {
            var contents = d.substring(d.indexOf('&')+1,d.length);
            var main = d.substring(d.lastIndexOf('?')+1,d.length-contents.length-1);
          }

          // These lines set the URL of the contents and main framesets if required
          if(main!='') top.frames["main"].document.location.href=main;
          if(contents!='') top.frames["contents"].document.location.href="/search/ovsearch.asp?" + contents;
          }


/////// ************************** CML Site frame page loading and resizing **********************
/////// ** Requires 2 frames (contents(left) & main(right) with optional 3rd frame (results - bottom left)
/////// ** and css classes frameContainerLeft, frameContainerRight for resizing
//////

// loadRefs & goSetHeight normally called together by the "loadPage" function
function loadRefs() {
var d=document.location.search;

          //
          // Bit of explanation called for here...
          // This page has 2 frames - "Main" (right frame) & "Contents" (left)
          //   and can be called with 2 parameter sets, separated by "?" - for example...

          //   i.e http://www.cmlmicro.com/Products/Index.asp?http://www.cmlmicro.com/Products/land/WDland.htm& 
          //http://www.cmlmicro.com/search/OVSearch.asp

          if (d.indexOf('&')== -1) {
            var contents = "";
            var main = d.substring(d.lastIndexOf('?')+1,d.length);
          } else {
            var contents = d.substring(d.indexOf('&')+1,d.length);
            var main = d.substring(d.lastIndexOf('?')+1,d.length-contents.length-1);
          }

          // These lines set the URL of the contents and main framesets if required
          if(main!='') top.frames["main"].document.location.href=main;
          if(contents!='') top.frames["contents"].document.location.href=contents;
          }

// below is script to RESIZE BROWSER WINDOW for varying height frames

function goSetHeight() {
  // changed document.getElementById to parent.document.getElementById
  var contentHeight = parent.document.getElementById('contents').contentWindow.document.body.scrollHeight;
  //alert(contentHeight);
  var mainHeight = parent.document.getElementById('main').contentWindow.document.body.scrollHeight;
  //alert(mainHeight);
  var y = parent.document.getElementById('frameContainerLeft');
  var z = parent.document.getElementById('frameContainerRight');
  // offset is height of header graphic plus menu
  var offset = 235;
  var minHeight = 2500;

  if(mainHeight > contentHeight) {
    var yHeight = (mainHeight + offset);
    var zHeight = (mainHeight + offset);
    //y.style.height = (mainHeight + offset) + "px";
    //z.style.height = (mainHeight + offset) + "px";
  } else {
    var yHeight = (contentHeight + offset);
    var zHeight = (contentHeight + offset);
    //y.style.height = (contentHeight + offset) + "px";
    //z.style.height = (contentHeight + offset) + "px";
  }
  if(yHeight < minHeight) {
    yHeight = minHeight;
    zHeight = minHeight;
  }
  // the next two lines actually do the work, but I've commented these out at the moment, as this
  // routine is causing more problems than it solves
  //y.style.height = yHeight + "px";
  //z.style.height = zHeight + "px";
  //alert(y.style.height);
  //alert(z.style.height);
}

//function goSetHeight2() {
//  alert("goSetHeight2");
//  var contentHeight = parent.document.getElementById('contents').contentWindow.document.body.scrollHeight;
//  //alert(contentHeight);
//  var mainHeight = parent.document.getElementById('main').contentWindow.document.body.scrollHeight;
//  //alert(mainHeight);
//  var y = parent.document.getElementById('frameContainerLeft');
//  var z = parent.document.getElementById('frameContainerRight');
//  // offset is height of header graphic plus menu
//  var offset = 135;
//  if(mainHeight > contentHeight) {
//    y.style.height = (mainHeight + offset) + "px";
//    z.style.height = (mainHeight + offset) + "px";
// } else {
//    y.style.height = (contentHeight + offset) + "px";
//    z.style.height = (contentHeight + offset) + "px";
//  }
//
//}
// above is script to RESIZE BROWSER WINDOW for varying height frames

// loadPage - calls loadRefs & goSetHeight - place in body tag OnLoad
function loadPage() {
         loadRefs();
         setTimeout('goSetHeight()',400);
         //goSetHeight();

}

// loadSearchPage - calls loadRefs & goSetHeight - place in body tag OnLoad
function loadSearchPage() {
         loadSearchRefs();
         setTimeout('goSetHeight()',400);
         //goSetHeight();

}
// loadSearchPage2 - calls loadRefs & goSetHeight, but waits for a end tag - place in body tag OnLoad
// NOTE:  This could cause problems, as there is no get-out clause!
function loadSearchPage2() {
         loadSearchRefs();
         var waitFlag = 0;
         do
         {
           //alert('Waiting')
         }
         while (document.getElementById('end') != null)

         setTimeout('goSetHeight()',400);

}
/////// ************************** END OF SEGMENT ************************************************



/////// ************************** CML Site showing hidden elements ******************************
/////// ** Requires items to be hidden to be in TBODY tags
//////

function showItems() {
         document.getElementById('trHide1').style.display='';
}

function showItems2() { /* this script shows all TBODY tags when called by SHOW Button */
         var arr = document.getElementsByTagName('tbody');
         for (i=0;i<arr.length;i++) {
             //alert(arr[i].InnerHTML);
             arr[i].style.display='';
             };
}
// showItems3 - Another method of showing rows - use this one if IE6 is giving problems....
function showItems3() {
         var arr = document.getElementsByTagName('tbody');
         for (i=0;i<arr.length;i++) {

             if(arr[i].style.display = 'none') {
                arr[i].style.display = '';
             }

             };
}


//function toggleTbody(id) {
//         var tbod = document.getElementById(id);
//         if(tbod) {
//         (tbod = (tbod.style || tbod)).display = (tbod.display == 'none') ? '' : 'none';
//}


// showHidden - shows the hidden tbody tags, and then resets the frame heights
// Note - the goSetHeight function shoudl no longer be required as Roger found a way in CSS
function showHidden() {
         //setTimeout('goSetHeight()',400);
         showItems3();
         //setTimeout('goSetHeight()',400);

}

// showHidden2 - same as showHidden, but waits for a particular element to be present before running....
function showHidden2() {
         var waitFlag = 0;
         do 
         {
           if (document.getElementById('end') != null) {
             showItems2();
             setTimeout('goSetHeight()',400);
             waitFlag = 10;
           } else {
             setTimeout('goSetHeight()',400);
             waitFlag++;
           }
         }
         while (waitFlag <= 9)

}

/////// ************************** END OF SEGMENT ************************************************

