var soundEmbed = null;

/* popup page */
function pop(url, w, h) {
  win=window.open(url,'tCw','width=' + w + ',height=' + h + ',resizable=1,scrollbars=1');
  if (win.opener) { win.moveTo(0,0); } else { win.opener=self; }
  if (win.focus) win.focus();
} 

/* link from popup to orig page */
function origPage(url)
{
	opener.location.href = url;
}

function toggle (id) {
  el = document.getElementById (id);
  cls = el.className;
  action = 0;
  if (cls.lastIndexOf ('_Co') == cls.length - 3) {
    openDiv (el);
  }
  else if (cls.lastIndexOf ('_Ex') == cls.length - 3) {
    closeDiv (el);
  }
}

function openDiv (el) {
  cls = el.className;
  clsPre = cls.substring (0, cls.length - 3);
  el.className = clsPre + '_Ex';
  img = document.getElementById (el.id + '_');
  img.src = img.src.replace ('open', 'close');
}
function closeDiv (el) {
  cls = el.className;
  clsPre = cls.substring (0, cls.length - 3);
  el.className = clsPre + '_Co';
  img = document.getElementById (el.id + '_');
  img.src = img.src.replace ('close', 'open');
}


/*  */
function showhide(id) {
  var divElement = document.getElementsByName(id);
  var de = document.getElementById('openerDiv'); 
   var text_openerDiv_O =
    '<img src="/products/mathematica/newin6/images/openSquare.gif" width="11" height="11" border="0"/> hide input';
  var text_openerDiv_C =
    '<img src="/products/mathematica/newin6/images/closeSquare.gif" width="11" height="11" border="0"/> show complete <i>Mathematica</i> input';
  for(i=0; i<divElement.length; i++) {
    if (divElement[i].className == 'inoutLabel') { 
      divElement[i].className = 'inoutLabel_Hide'; 
    } else if (divElement[i].className == 'inoutLabel_Hide') {
      divElement[i].className = 'inoutLabel'; 
    } else if (divElement[i].className == 'inputState') { 
      divElement[i].className = 'inputState_Hide'; 
    } else if (divElement[i].className == 'inputState_Hide') {
      divElement[i].className = 'inputState'; 
    } else if (divElement[i].className == 'label_Hide') { 
      divElement[i].className = 'label_Show'; 
    } else if (divElement[i].className == 'label_Show') {
      divElement[i].className = 'label_Hide'; 
  } }
/* 
 if (de.className == 'opencloseDiv_O') {
    de.className == 'opencloseDiv_C';
    document.getElementById('openerDiv').innerHTML = "open";
  } else if (de.className == 'opencloseDiv_C') {
    de.className == 'opencloseDiv_O';
    document.getElementById('openerDiv').innerHTML = "close";
  }
*/
  img = document.getElementById('inGroup_'); 
  if (img.src.indexOf('showInputRed.gif') > 0) {
    img.src = img.src.replace ('show', 'hide');
  } else {
    img.src = img.src.replace ('hide', 'show');
  }
  if (img.src.indexOf('openInput.gif') > 0) {
    img.src = img.src.replace ('openInput', 'closeInput');
  } else {
    img.src = img.src.replace ('closeInput', 'openInput');
  }
  img2 = document.getElementById('tdSpacer_'); 
  if (img2.src.indexOf('wideSpacer.gif') > 0) {
    img2.src = img2.src.replace ('wide', 'narrow');
  } else {
    img2.src = img2.src.replace ('narrow', 'wide');
  }

} 

/*  showInputForm */
function input(i) {
  id_out = i + '_out';
  id_in = i + '_in';
  el_out = document.getElementById (id_out);
  el_in = document.getElementById (id_in);
  if (!el_in) {
    el_url = "HTMLFiles/Integrate.en/" + i + ".txt";
    req = false;
    if (window.XMLHttpRequest) {
      try { req = new XMLHttpRequest (); }
      catch (e) { req = false; }
    }
    else if (window.ActiveXObject) {
      try { req = new ActiveXObject ("Msxml2.XMLHTTP"); }
      catch (e) {
        try { req = new ActiveXObject ("Microsoft.XMLHTTP"); }
        catch (e) { req = false; }
      }
    }

    function addInputForm () {
      if (req.readyState == 4) {
        if (req.status == 200) {
          el_out.innerHTML = req.responseText;
        } else {
          alert ("An error occurred while retrieving the file:\n" + el_url);
        }
      }
      el_in = document.getElementById (id_in);
      return el_in.style.visibility == 'visible' ? hideLayer(id_in) : showLayer(id_in);
    }
    if (req) {
      try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
      } catch (e) {
        alert (e);
      }

      req.onreadystatechange = addInputForm;
      // broken here on gecko:
      try {
        req.open ("GET", el_url, true);
      } catch (e) {
        alert (e);
      }
      req.send ("");
    }
  }
/*
  else if (el_in.className == 'InputFormText' || el_in.className == 'IFT') {
    rows = el_in.innerHTML.split('\n').length + 1;
    for (ch = el_out.firstChild; ch; ch = ch.nextSibling) {
      if (ch.className == 'IFU') {
        var url = ch.innerHTML
      }
    }
*/
  else if (el_in.className == 'InputFormText' || el_in.className == 'IFT') {
   if (el_in.firstChild.nodeType == 1) {
      el_in = el_in.firstChild;
    }
    var innertxt = el_in.innerHTML.replace(/(\r|\n)+/g, '\n');
    rows = innertxt.split('\n').length + 1;
    for (ch = el_out.firstChild; ch; ch = ch.nextSibling) {
      if (ch.className == 'IFU') {
          var url = ch.innerHTML
      }
    }

    /* We use .innerHTML when we want &lt; and .firstChild.nodeValue when we want < */
    div = '<div name="' +id_in+ '" id="' +id_in+ '" class="IFF">'
        + '<div><textarea rows="' +rows+ '">' +innertxt+ '</textarea><br />'
        + '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td><div> </div></td><td align="right">'
    if (url) { div += '<span class="IFU">' + url + '</span>' }
        + '</td></tr></table></div>'
    div += '<a href="javascript:hideLayer(' +"'" +id_in+ "'"+ ')">x</a></div>';
    el_out.innerHTML = div;
    showLayer(id_in);
  }
  else {
    // We've already downloaded the layer
    return el_in.style.visibility == 'visible' ? hideLayer(id_in) : showLayer(id_in);
  }
}

function showDetail (id) {
  var el = document.getElementById (id);
  /* pause before popping up window */
  Pause(150);
  for (var div = el.firstChild; div; div = div.nextSibling) {
    if (div.nodeType == 1) { break; }
  }
  if (div.className == 'DetailLayerBox' ) {
    var ndiv = '';
    var width = 0;
    for (var li = div.firstChild; li; li = li.nextSibling) {
      if (li.nodeType == 1) {
        ndiv += '<div><a href="' + li.getAttribute ('href') + '">';
        ndiv += li.innerHTML + '</a></div>';
        width = Math.max (width, li.firstChild.nodeValue.length);
      }
    }
    ndiv = '<div">' + ndiv + '</div>';
    /*  alert(ndiv);  */
    el.innerHTML = ndiv;
    el.style.cssText = el.style.cssText + ';width:' + (0.6*width+2) + 'em;';
  }
  var hel = document.getElementById ('head_'+id.slice(6));
  if (hel) {
    for (var ha = hel.firstChild; ha; ha = ha.nextSibling) {
      if (ha.nodeType == 1) { break; }
    }
    hel.style.backgroundColor = '#646AC8';
    ha.style.color = '#ffffff';
  }
  showLayer (id);
}
function hideDetail (id) {
  var hel = document.getElementById ('head_'+id.slice(6));
  if (hel) {
    for (var ha = hel.firstChild; ha; ha = ha.nextSibling) {
      if (ha.nodeType == 1) { break; }
    }
    hel.style.backgroundColor = '';
    ha.style.color = '';
  }
  hide2 (id);
}

function Pause(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
} 


function ShowStatus(msg) { window.status = msg; return true; }



function swap(obj, theWidth, theHeight, fileName, divId){
var flash1='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+ theWidth + '" height="'+ theHeight + '" id="benefits" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="'+ fileName + '" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="'+ fileName + '" loop="false" menu="false" quality="high" bgcolor="#ffffff" width="'+ theWidth + '" height="'+ theHeight + '" name="benefits" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';

	document.getElementById(divId).innerHTML = flash1;
}


function playSound(url) {
soundStop();
soundEmbed = document.createElement("embed");
soundEmbed.setAttribute("src", url);
soundEmbed.setAttribute("hidden", true);
soundEmbed.setAttribute("autostart", true);
document.body.appendChild(soundEmbed);
}

function soundStop() {
if ( soundEmbed ) document.body.removeChild(soundEmbed);
soundEmbed = null;
}
