/***********************************************
// primary site navigation script //

* Switch Content script- ? Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use. Last updated Mar 23rd, 2004.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var enablepersist="off" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="yes" //Collapse previously open content when opening present? (yes/no)

var contractsymbol='- ' //HTML for contract symbol. For image, use: <img src="whatever.gif">
var expandsymbol='+ ' //HTML for expand symbol.

if (document.getElementById){
document.write('<style type="text/css">')
document.write('.submenu{display:none;}')
document.write('</style>')
}

function getElementbyClass(rootobj, classname){
var temparray=new Array()
var inc=0
for (i=0; i<rootobj.length; i++){
if (rootobj[i].className==classname)
temparray[inc++]=rootobj[i]
}
return temparray
}


function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expand(curobj, cid){
var spantags=curobj.getElementsByTagName("SPAN")
var showstateobj=getElementbyClass(spantags, "showstate")
if (ccollect.length>0){
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
if (showstateobj.length>0){ //if "showstate" span exists in header
if (collapseprevious=="no")
showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
else
revivestatus()
}
}
}

function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function revivestatus(){
var inc=0
while (statecollect[inc]){
if (ccollect[inc].style.display=="block")
statecollect[inc].innerHTML=contractsymbol
else
statecollect[inc].innerHTML=expandsymbol
inc++
}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}

document.cookie=window.location.pathname+"="+selectedItem
}

/**
* Stop-gap function to fix an incorrect image src in the margin calc and thoeretical calc.
* Calculator HTML is referring to Remove.htm" in the image src rather than "remove.gif"
* Fixes the image reference for this image in the help text near the bottom of the page.
*
*/
function fixCalcaulatorImages() {
  var imgs = document.getElementsByTagName('img');
  for (var i = 0; i < imgs.length; i++)
  {
    if (imgs[i].src.indexOf('Remove.gif')) {
      imgs[i].src = imgs[i].src.replace('Remove.gif','remove.gif');
    }
  }
}

function do_onload(){

  if (location.href.toLowerCase().indexOf('/opc/opcmargins') != -1) {
    fixCalcaulatorImages();
  }

uniqueidn=window.location.pathname+"firsttimeload"
var alltags=document.getElementsByTagName("ul")
ccollect=getElementbyClass(alltags, "submenu")
statecollect=getElementbyClass(alltags, "showstate")
if (enablepersist=="on" && ccollect.length>0){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
if (ccollect.length>0 && statecollect.length>0)
revivestatus()
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate

/***********************************************
// switch tabs in cross-sells //
***********************************************/

var persistmenu="no" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="local" //enter "sitewide" for menu to persist across site, "local" for this page only

if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.option{display: none;}\n')
document.write('</style>\n')
}

function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("classes").getElementsByTagName("div"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="option") //DynamicDrive.com change
				ar[i].style.display = "none";
				
			}
			el.style.display = "block";
			
		}
	}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function onloadfunction(){
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!="")
document.getElementById(cookievalue).style.display="block"
}
}

function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
blockid="sub"+inc
break
}
inc++
}
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
}

if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
window.onload=onloadfunction

if (persistmenu=="yes" && document.getElementById)
window.onunload=savemenustate

/***********************************************
// secondary site navigation script //
***********************************************/

function expandCollapse() {
	for (var i=0; i<expandCollapse.arguments.length; i++) {
		var element = document.getElementById(expandCollapse.arguments[i]);
		element.style.display = (element.style.display == "block") ? "none" : "block";
	}
}

/***********************************************
Change classname of widget tabs to active/inactive
***********************************************/

function toggle(linkObj)
{
	var node = linkObj; //start
	while (node && node.nodeName.toUpperCase() != 'UL') //node exists, isn't UL
		node = node.parentNode; //go up
	var tabs = node.getElementsByTagName('a'), //got it, get collection
	tab,
	t = 0;
	while (tab = tabs[t++])
		if (tab == linkObj)
			tab.className = 'active';
		else tab.className = 'inactive';
	return false;
}

/***********************************************
open clickable headings
***********************************************/

function ShowColumn(url, title) {
    window.open(url, title,"top=0,left=0,width=500,height=350,scrollbars=yes,resizable=yes")
}

/***********************************************
resolution sniffer to alter page styles depending on screen realestate
***********************************************/

function checkBrowserWidth()
{
	var theWidth = getBrowserWidth();

	if (theWidth < 950)
	{
		setStylesheet("small");
	}
	else
	{
		setStylesheet("normal");
	}
	
	return true;
}

function getBrowserWidth()
{
	if (window.innerWidth)
	{
		return window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth != 0)
	{
		return document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		return document.body.clientWidth;
	}
	
	return 0;
}

function setStylesheet(styleTitle)
{
	var currTag;

	if (document.getElementsByTagName)
	{
		for (var i = 0; (currTag = document.getElementsByTagName("link")[i]); i++)
		{
			if (currTag.getAttribute("rel").indexOf("style") != -1 && currTag.getAttribute("title"))
			{
				currTag.disabled = true;

				if(currTag.getAttribute("title") == styleTitle)
				{
					currTag.disabled = false;
				}
			}
		}
	}
	
	return true;
}

/***********************************************
script to run customer view select dropdown
New script followed by older redundant
***********************************************/

function go()
{
	box = document.forms[1].more;
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = destination;
}

function load_page(which_form) {
self.location.href=which_form.more.options[which_form.more.selectedIndex].value;
}

/***********************************************
// glossary popup javascript //
***********************************************/

function doOpen(filename) {

self.open("http://www.asx.com.au/webmcq/servlet/com.webmcq.glossary.Glossary?cid=0&word="+filename+"&alt=1", "_blank", "width=470,height=350,menubar=0,toolbar=0,scrollbars=1,resizable=1");


}
function pageOpen(filename) {

self.open(filename, "_blank", "width=600,height=400,menubar=1,toolbar=1,scrollbars=1,resizable=1");

}


/***********************************************
SEO tracking code from realmedia
***********************************************/

var strTrackingPage = window.document.location + ' ';  /* Check to see if the page is secure */
var refr=escape(document.referrer); /* get the http referer and encode it */
var dom=location.hostname; /* get the host domain */

if (strTrackingPage.indexOf('https') != -1)
{
stURL="https://au.track.decideinteractive.com/n/7700/7702/www.asx.com.au/c3a03f3b002503000000000600000000027bf1c60000000000000000000000000000000100/i/c?0&1pixgif&referer="
+ refr;
}
else
{
stURL="http://au.track.decideinteractive.com/n/7700/7702/www.asx.com.au/c3a03f3b002503000000000600000000027bf1c60000000000000000000000000000000100/i/c?0&1pixgif&referer="
+ refr;
}

if (refr&& refr.search(dom) == -1) /* if the referrer is external preload the image request */
{
imageTR = new Image();
imageTR.src = stURL;
}
/***********************************************
end SEO tracking code from realmedia
***********************************************/



/***********************************************
pre-redesign contents of global.js. not sure where this file used
***********************************************/

function goTo(url) {
    window.location = url
}




