<!--
/*  Javascript
    NEWS SUBSET COMMON
	
	index ->	
			support checking
			show/hide divs
			aegis stock box
			left navigation right border
			masthead box component
			classifieds box
			etrade stock price form code
			weather
			cookies
			lead story resize
*/


/* ----- =support checking ----- */
/* ---------------------------- */

// detect browser support for getElementById and createElement

var canGetElem = false;
var canCreateElem = false;

if (document.getElementById) {
    canGetElem = true;
    if (document.createElement) {
        canCreateElem = true;
    }
}

var userWidth;
var docLoaded = false;
var scrollaExist = false;
var criticalRes = 925;

// resolution above which large widths are used
function doOnLoad() {
    docLoaded = true;
	// initialise scrollamatic for pages that have one
    if (currentPage.substring(0, 15) == "ninews_homepage" || currentPage == "niclassifieds_homepage" || currentPage == "ninews_multimedia") {
		// and flag that a scrollamatic exists
        scrollaExist = true;
        initScrollers();
    }
    //randomPaper(); 				// masthead paper box
    rotateWeather(0); 			// weather box rotation
	setLeftnavLineLength(); 	// left nav right border length
}

function getElementsByClassName(clss, prnt, tg) {
    var elements = new Array();
    tg = tg || '*';
    prnt = prnt || document;
    var list = prnt.getElementsByTagName(tg);
    for (var i = 0; i < list.length; ++i) {
        if (list[i].className == clss) {
            elements.push(list[i]);
        }
    }
	return elements;
}

function findPosY(obj) {
    /* Find Position script by:
       Peter-Paul Koch
       http://www.quirksmode.org */
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
        }
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
    /* end Find Position script */
}


/* ---- =show / hide divs ---- */
/* --------------------------- */

/* generic function for hiding / showing divs with links
   currently used on 	-> Home Page (breaking news box)
						-> Business Section (market update tabs)					
*/

function hasParent(e, id) {
	if (!e.parentNode) return false;
	if (e.parentNode.id == id) return e.parentNode;
	
	return hasParent(e.parentNode, id);
}

function showBNDiv(e) { // show divs and active tab for each section
  var eNews = hasParent(e, 'showHide');
  
  if (eNews) {
    eNews.className = e.id;
	}
}

/* -- show / hide for aegis market component  -- */
/* used for business home, world and market page */

function checkAegis() {
	/* temp removed! lose/gain may return */
	/* if (currentPage == "nibusiness_markets") {
		document.getElementById('loseGainTop').style.display = "block";
		document.getElementById('loseGainBot').style.display = "block";
	} */
	if (currentPage == "nibusiness_world") {
		document.getElementById('ordsImg').style.display = "none";
		document.getElementById('ordsHead').style.display = "none";
		document.getElementById('oilImg').style.display = "block";
		document.getElementById('oilHead').style.display = "block";
	} else {
		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;
}


/* ---- =left navigation right border ---- */
/* --------------------------------------- */

function setLeftnavLineLength() {
    if (canGetElem&&document.getElementById("contentWrap")) {
		// find height of middle content or height of right column, whichever is taller
        tmpHeight = Math.max(document.getElementById("contentWrap").offsetHeight, document.getElementById("rightnav").offsetHeight);
		if (document.getElementById("leaderboardAd") && (userWidth > criticalRes)) {
            tmpHeight += document.getElementById("leaderboardAd").offsetHeight;
            tmpHeight += 10;
        }
        
		currentLeftNavHeight = document.getElementById("leftnavPrimary").offsetHeight;
		
        // tmpHeight += "px";
		
		// If left nav isn't already taller
		if(tmpHeight > currentLeftNavHeight) {
		    // set height of leftnav to height determined above
            document.getElementById("leftnavPrimary").style.height = tmpHeight+"px";
		}
    }
}


/* ---- =masthead box component ---- */
/* --------------------------------- */

/*var paperLink;
var theSelect;

function loadPaperImage(theSelect) {
	pictmp = new Image(126,178);
	pictmp.src = metaPaper[theSelect.value][2];
	document.images["paperPlace"].src = eval("pictmp" + ".src");
	paperLink=metaPaper[theSelect.value][0];
}

function papersLink(dest) {
	ptmp = document.papersDrop.papersDropSelect.options[document.papersDrop.papersDropSelect.selectedIndex];
	if (dest=="site") {
	window.location=paperLink;
	}
	if (dest=="delivery") {
	window.location=metaPaper[ptmp.value][1];
	}
}

function randomPaper() {
	var randomPaper=Math.floor(Math.random()*metaPaper.length) // no. of papers
	//document.papersDrop.papersDropSelect.selectedIndex=randomPaper;
	ptmp = document.papersDrop.papersDropSelect.options[document.papersDrop.papersDropSelect.selectedIndex];
	paperLink = ptmp.value;
	loadPaperImage(ptmp);
}*/


/* ----- =classifieds box ---- */
/* --------------------------- */

function clearTabs() {
    if (canGetElem) {
    
        // clear all blue color tabs during div changes
    	document.getElementById("jobsActive").style.display = "none";
        document.getElementById("carsActive").style.display = "none";
    	document.getElementById("matchActive").style.display = "none";
		document.getElementById("localActive").style.display = "none";
        
    }
}

function clearDivs() {
    if (canGetElem) {
    
        // clear all divs on page refresh / load
    	document.getElementById("jobs").style.display = "none";
        document.getElementById("cars").style.display = "none";
    	document.getElementById("match").style.display = "none";
		document.getElementById("local").style.display = "none";
        
    }
}
	
function show_div(id) {
    if (canGetElem) {
    
        // show divs and active tab for each section
    	clearDivs();
        document.getElementById(id).style.display = "block";
            // turns on active div content layer
    	clearTabs();
    	document.getElementById(id + "Active").style.display = "block";
            // turns on active tab div layer

    }
}

function randomDiv() { 
   // choose random id for classified tabs.
   var whichDiv = Math.floor(Math.random()*2);   
   var div = new Array(3)
   div[0]="jobs";
   div[1]="cars";
   div[2]="match";
   // apply random id on refresh   
   show_div((div[whichDiv]));
}

 
function ValidateForm(f) {
		if (f.make_id.selectedIndex == 0) {
			 alert("You need to specify a make");
			 f.make_id.focus();
			 return false;
		}
		
		
		f.action="http://search.carsguide.news.com.au/news/find-a-car/power-search/search-results.do";
		
		return true;
	}
	
function ChangeType(f) {
	//Change the values in the make dropdown
	if (f.search_type.options[f.search_type.selectedIndex].value == 1)
	{
		//We have Dealer cars
		//First clear the location dropdown
	    for (i=f.region_id.length-1; i>=0; i--)
	    	f.region_id.options[i] = null
		//Now fill it with the correct value	
	    f.region_id.options[0] = new Option("Any Location","Any Location")
	    f.region_id.options[1] = new Option("ACT","ACT")
	    f.region_id.options[2] = new Option("NSW","NSW")
	    f.region_id.options[3] = new Option("QLD","QLD")
	    f.region_id.options[4] = new Option("SA","SA")
	    f.region_id.options[5] = new Option("TAS","TAS")
	    f.region_id.options[6] = new Option("VIC","VIC")
	    f.region_id.options[7] = new Option("WA","WA")										
	}
	else
	{
		//We have Classified cars	
		//First clear the location dropdown
	    for (i=f.region_id.length-1; i>=0; i--)
	    	f.region_id.options[i] = null
		//Now fill it with the correct value	
	    f.region_id.options[0] = new Option("Any Location","Any Location")
	    f.region_id.options[1] = new Option("Adelaide", "Adelaide")
	    f.region_id.options[2] = new Option("Brisbane","Brisbane")		
	    f.region_id.options[3] = new Option("Cairns","Cairns")		
	    f.region_id.options[4] = new Option("Charters Towers (Qld)","Charters Towers (Qld)")		
	    f.region_id.options[5] = new Option("Darwin","Darwin")		
	    f.region_id.options[6] = new Option("Gold Coast (Qld)","Gold Coast (Qld)")		
	    f.region_id.options[7] = new Option("Hobart","Hobart")		
	    f.region_id.options[8] = new Option("Melbourne","Melbourne")		
	    f.region_id.options[9] = new Option("Perth","Perth")		
	    f.region_id.options[10] = new Option("Sydney","Sydney")		
	    f.region_id.options[11] = new Option("Townsville","Townsville")		
	}

}

function validateC1(thef) {
	if (thef.keywords.value=="Keywords") {
		thef.keywords.value = " ";
	}
}


/* ---- =etrade stock price form code ---- */
/* --------------------------------------- */

function displayProductSearch() {
	newwindow = window.open("https://www.etradeaustralia.com.au/Application/ProductSearch/ProductSearch.asp", "ProductSearch", "dependent=no,height=350px,width=320px,scrollbars,resizable=yes,alwaysRaised=yes");
}
	
function doQuote() {
	var strURL;
	var strSymbol = escape(window.document.frmStockQuote.Code.value);
	var strExchange = window.document.frmStockQuote.Exchange[document.frmStockQuote.Exchange.selectedIndex].value;
	var strType = window.document.frmStockQuote.Type[document.frmStockQuote.Type.selectedIndex].value;
	strURL = "https://www.etradeaustralia.com.au/Products/StockCentre/StockCentre.asp?DisplayAs=Quotes&Code=" + strSymbol + "&Exchange=" + strExchange + "&Type=" + strType;
	document.frmStockQuote.URL.value = strURL;
	return true;
}


/* ---- =weather ---- */
/* ------------------ */

function setWeather(theoption) {
	if (theoption.options[theoption.selectedIndex].value == "more") {
		return false;
	}
	else {
		clearTimeout(wTime);
		tt="na";
		theplace = eval("w"+theoption.options[theoption.selectedIndex].value);
		updateWeatherDiv(theplace);
	}
}

var tts=0;
var wTime;
var tt="timer";

function rotateWeather(stateNum) {
	if (navigator.appName.indexOf("Microsoft") == -1) {
		//ranNumba=(wStates.length-1);
		//stateNum=Math.floor(Math.random()*ranNumba)
	}	
	if (tt=="timer") {
		/*stateNumx = wStates[stateNum];
		stateNumxy = eval(stateNumx);
		updateWeatherDiv(stateNumxy);*/
	}
}

function updateWeatherDiv(tp) {
	// city 
	document.getElementById("weatherCity").firstChild.nodeValue = tp[0];
	// forecast 
	document.getElementById("weatherForecast").firstChild.nodeValue = tp[2];	
	// hi low
	document.getElementById("weatherHiLow").firstChild.nodeValue = tp[4] +" - "+ tp[3];
	// image
	document.getElementById("weatherIcon").src = tp[1];
	if ((tt=="timer")&&(navigator.appName.indexOf("Microsoft") != -1)) {
		if (tts<(wStates.length-1)) {
			tts++;
		} else {
			tts=0;
		}	
		var wTime = setTimeout("rotateWeather(tts)",3200);
	} 
}


/* ---- =cookies ---- */
/* ------------------ */

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" : "");
}


	
//-->
