/*  Javascript News.com.au
	
	index ->	
			dropdown nav
			tertiary nav
			aegis quote box
			tab-o-matic		
			SWFObject
			Accipiter rewrite
*/

function renderAd(divName, aambTag) {
    var invObj = 'INV' + divName;
	var isMotif = 0;
	var templateKick = "<script type=\"text/javascript\">var inDapIF = true;</script>";    
    try { 
	    var aamCode = templateKick + eval(aambTag); 
		if(aamCode.indexOf('doubleclick') >= 0) {
		   isMotif = 1;
		}
		if(aamCode.indexOf("buster_url=" > 0)) {
		    aamCode = aamCode.replace("buster_url=", "buster_url=http://www.foxsports.com.au/atlas_rm.html");
		}
		aamCode += "<script type=\"text/javascript\">document.writeln('<scr' + 'ipt language=\"javascript\" defer=\"yes\">document.close();</scr' + 'ipt>'); </script>";

	}
    catch(aamErr) { }
      
    if (typeof(aamCode) != 'undefined') {   
        var msieIdx = navigator.userAgent.indexOf('MSIE');
        if(msieIdx > -1) {
            
            // IE
            var ifrString = '<iframe name="' + invObj + '" width="0" height="0" frameborder="0" AAM_EVENT="javascript:try { document.getElementById(\'' + divName + '\').insertAdjacentElement(\'beforeEnd\', window.frames[\'' + invObj + '\'].document.getElementById(\'adDiv\')) } catch(aamErr) { }"></iframe>';
               
            if(parseInt(navigator.userAgent.substring(msieIdx + 5).split(' ')[0]) < 7) {

                // IE6
				if(isMotif == 1) {
					    document.getElementById(divName).innerHTML += ifrString.replace(/AAM_EVENT/, 'onload');
				} else {
                   document.getElementById(divName).innerHTML += ifrString.replace(/AAM_EVENT/, 'onreadystatechange');
				}
                window.frames[invObj].document.writeln('<div id="adDiv">' + aamCode);

            } else {        
                // IE7 
                document.getElementById(divName).innerHTML += '<div id="TMP' + divName + '" style="display:none">' + escape('<body><div id="adDiv">' + aamCode + '</div>') + '</div>' + ifrString.replace(/AAM_EVENT/, 'onload');
                window.frames[invObj].document.location = 'javascript:unescape(parent.document.getElementById(\'TMP' + divName + '\').innerHTML)';
            }
               
            // Not IE         
        } else document.writeln('<div id="' + invObj + '" style="display:none">' + aamCode + '<script type="text/javascript" defer="true">document.getElementById(\'' + divName + '\').innerHTML = document.getElementById(\'' + invObj + '\').innerHTML;document.getElementById(\'' + invObj + '\').innerHTML = \'\';</scr' + 'ipt></div>');
    }
}


adsPainted = false;

function aamAppendNewIframes() {
	if (navigator.userAgent.toLowerCase().indexOf('firefox/1.') > -1) { 
		document.close();
		var allIframes = document.getElementsByTagName('iframe');
		var currIframe = new Array();
		for (a = 0; a < allIframes.length; a++)
		   currIframe[currIframe.length] = allIframes[a];         
		
		for (c = 0; c < currIframe.length; c++) {
		   var newIframe = document.createElement('iframe');
		   
		   newIframe.width = currIframe[c].width; 
		   newIframe.height = currIframe[c].height;            
		   newIframe.frameBorder = 0;
		   newIframe.scrolling = 'no';
		   newIframe.marginWidth = 0;
		   newIframe.marginHeight = 0;
		   newIframe.style.display = 'none';
		
		   currIframe[c].parentNode.appendChild(newIframe);
		   var newIframeDocument = newIframe.contentWindow.document;
		   newIframeDocument.open();
		   newIframeDocument.writeln('<html><head></head><body></body></html>');
		   newIframeDocument.close();
		}
	}                          
}



function isDefined(myObject) {
    return (typeof(myObject) != "undefined");
}


function selectedValue(nodeList) {
	for (var i=0; i<nodeList.length; i++) {
		if (nodeList[i].checked) {
		    return nodeList[i].value;
		}
	}
	
	return null;
}

function checkSiteVar() {
    niSearchForm = document.getElementById("ni-search");
	niSearchTerm = document.getElementById("ninnsearch");
	if(document.getElementById("local-search").checked) {
	    niSearchForm.setAttribute("action", "http://www.truelocal.com.au/oneBoxSearch.do");
		niSearchTerm.setAttribute("name", "term");
		niSearchForm.setAttribute("method", "get");
    } else {
	    niSearchForm.setAttribute("action", "http://searchresults.news.com.au/servlet/Search");
		niSearchTerm.setAttribute("name", "queryterm");
		niSearchForm.setAttribute("method", "get");
	}
	niSearchForm.submit();
}


function pollSubmit(pollForm) {
	var option = selectedValue(pollForm.option);
	var addr   = pollForm.action + "?option="+option;

	window.open(addr, 'nipoll', 'width=550, height=450'); 
		
	return false;
}

/* ---- =aegis stock box ---- */
/* -------------------------- */

// pull stock quote form data and append to url
function goStockUrl() {
	var quoteID = document.getElementById('quote').value;
	window.location.href = "http://markets.news.com.au/newscorp/entry.aspx?secid=" + quoteID;
}

/* font size change 
------------------- */

var curFontSize = 1; 	
var fontModifier = 0.1; 	

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) {
	    endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

function FixCookieDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)  {
		date.setTime (date.getTime() - skew);
	}
}

function GetCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i=0;
	while (i < clen) {	
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
		    return getCookieVal (j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i === 0) {
		    break;
		}
	}
	return null;
}

function SetCookie(name,value,expires,path,domain,secure) {
	document.cookie = name + "=" + escape (value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}

/* insert hi-res logo and call window print */
function printStoryPage() {
	 if (document.getElementById("print-logo")){
         document.getElementById("print-logo").setAttribute("src", "/entertainment/images/print/print-logo.jpg");
	     window.print();
	 }
}

function fontSize(act) {
    if (document.getElementById) {
        storyBody = document.getElementById("text-big");
		storyComments = document.getElementById("story-comments");
        if (act === 1) {
            curFontSize += fontModifier;
            curFontSize = Math.min(curFontSize, 1.4);
        } else if (act === 0) {
            curFontSize -= fontModifier;
            curFontSize = Math.max(curFontSize, 1);
        }
        storyBody.style.fontSize = curFontSize + "em";
		
		if(storyComments !== null) {
		    for (v = 0; v < storyComments.getElementsByTagName("blockquote").length; v++) {
		       storyComments.getElementsByTagName("blockquote")[v].style.fontSize = curFontSize + "em";
		    }
		}
    }
	
	// set cookie with font size
	var expdate = new Date();
	FixCookieDate (expdate);
	expdate.setTime (expdate.getTime() + (672*60*60*1000)); // 4 weeks
	SetCookie("userfontc",curFontSize,expdate);		
	
	return(false);
}


function sizeImageCaption() {
	var galleryImgSize = document.getElementById("gallery-image").offsetWidth;
	document.getElementById("image-border").style.width = galleryImgSize + "px";
	document.getElementById("image-border").style.visibility = "visible";
	document.getElementById("image-border").style.border = "1px solid #cfcfcf";
	galleryImgSize += 4;
	document.getElementById("gallery").style.width = galleryImgSize + "px";
	document.getElementById("gallery").style.visibility = "visible";
	document.getElementById("gallery-image-caption").style.display = "block";
}

function sizedPopUp(url, width, height, bars, isResizable) {
    var setResizable = "yes";
    if(isResizable != null) {
	    if(isResizable === "no");
	    setResizable = "no";
	}
	window.open(url, '',
	'width=' + width + ',height=' + height + ' ,scrollbars=' + bars + 
	    ',status=yes,toolbar=no,menubar=no,location=no,resizable='+setResizable);
}


function linkDropSelect(select) {
	var selectedURL = select.options[select.selectedIndex].value;
	window.location.href = selectedURL;
}

function linkDropSelectButton(form) {
var selectedURL = form.getElementsByTagName("SELECT")[0].value;	
	window.location = selectedURL;
	return(false);
}

/* for yahoo content matching */
function showListings(parentElementId, ulClassName) {
    var i=6;	
	var newUL = document.createElement("ul");
	newUL.setAttribute("class", ulClassName);
	if(typeof(zSr) == "undefined") {
	    return false;
	}
    while (i < zSr.length) {
        var descr = zSr[i++]; // listing description
		if(descr.length > 100) {
		    descr = descr.substring(0, 100) + "\u2026";
		}
        var unused1 = zSr[i++]; // (ignore)
        var clickURL = zSr[i++]; // listing link
        var title = zSr[i++]; // listing title
        var sitehost = zSr[i++]; // advertiser's domain name
        var unused2 = zSr[i++]; // (ignore)
	    var newLI = document.createElement("li");
		var newA = document.createElement("a");
		newLI.appendChild(newA);
		newA.setAttribute("target", "_new");
		newA.setAttribute("href", clickURL);
		var newSpan = document.createElement("span");
		newA.appendChild(newSpan);
		var newStrong = document.createElement("strong");
		newSpan.appendChild(newStrong);
		var newTextTitle = document.createTextNode(title);
		newStrong.appendChild(newTextTitle);
		var newBr = document.createElement("br");
		newSpan.appendChild(newBr);
		var newTextDescr = document.createTextNode(descr);
		newSpan.appendChild(newTextDescr);
		
		newUL.appendChild(newLI);
	}
	document.getElementById(parentElementId).appendChild(newUL);
	
}

/* =dropdowns/hover for ie - 
needs to be called with the root 
----------------- */

// IE only function
startList = function(elementId) {
	if (document.all && document.getElementById) {
	    navRoot = document.getElementById(elementId);
	    if (!navRoot) {
	        return(false);
	    }
		for (i=0; i<navRoot.childNodes.length; i++) {
		    node = navRoot.childNodes[i];
			if ( (node.nodeName=="LI") || (node.nodeName=="DL") || (node.nodeName=="DD") || (node.nodeName=="DT") ) {
				node.onmouseover = function() {
				    this.className+=" over";
				}
				node.onmouseout = function() {
				    this.className=this.className.replace(" over", "");
				}
			}
		}
	}
} 



/* =tab-o-matic
--------------- */
function hasParent(e, id) {
	if (!e.parentNode) {
	    return false;
	}
	if (e.parentNode.id == id) {
	    return e.parentNode;
	}
	
	return hasParent(e.parentNode, id);
}

// right hand nav tab function
function showCBox(e) {  // show divs and active tab for each id (tab and div)
  var eNews = hasParent(e, 'classifieds');
  
  if (eNews) {
    eNews.className = e.id;
  }
}


// homepage state news tab function
function showSBox(e) {  
  var eLogin = hasParent(e, 'dodol');
  
  if (eLogin) {
    eLogin.className = e.id;
  }
}


// local tv/movie guide tab function
function showLocDiv(e) {  
  var eNews = hasParent(e, 'guide');
  if (eNews) {
    eNews.className = e.id;
  }
}

// music charts
function showChartDiv(e) {  
  var eNews = hasParent(e, 'music-charts');
  if (eNews) {
    eNews.className = e.id;
  }
}


// ent charts
function showEntChartDiv(e) {  
  var eNews = hasParent(e, 'ent-charts');
  if (eNews) {
    eNews.className = e.id;
  }
}

// market data last updated
function showLuMd(e) {  
  var eNews = hasParent(e, 'market-data-tables');
  if (eNews) {
    eNews.className = e.id;
  }
}

// fox sports drop zones
function showBNDiv(e) { 
  var eNews = hasParent(e, 'thumb-toggle');
  if (eNews) {
    eNews.className = e.id;
	}
}

// currencies last updated
function showLuCurr(e) {  
  var eNews = hasParent(e, 'currencies-tables');
  if (eNews) {
    eNews.className = e.id;
  }
}
