﻿// ------------------------------------------------------------------------------------------------
// Header.js (NineMSN Australia) - Copyright (c) 2000-2006 ninemsn. All Rights Reserved.// 
// 
//// $Header:  /share/js/header.js,v 0.2.2 2006/05/18 Exp $
// ------------------------------------------------------------------------------------------------

var _imgFolder = "img/hd2008/";
var _imgURL = _spacURL + _imgFolder;
var _nmsnPart;
var _nmsnBanner;
var _nmsnCustomTargets='';
var _nmsnCallLoc;
var _nmsnSite;
var _nmsnSection;
var _nmsnSubsection;
var _expandingMidbar;
//Omniture declarations
var _nmsnOCategory="";
var _nmsnOCompany="";
//Declare ninemsn links target variable (only used for lavalife)
var _nmsnATarget;
var _nmsnHeader;
var _nmsnOEnabled;
var _nmsnSitewidth;
var _nmsnOptusHeaderWidth;
var _nsmnOptusSpacerWidth;
var _nmsnHeaderwidth;
var _nmsnTakeover;
var _nmsnFormEnabled;
var _nmsnPlatformNineCall;

//Specify how all ninemsn links will open on the page (only used for lavalife)
if (_nmsnATarget!=undefined){
	_nmsnATarget = _nmsnATarget;
}else{
	var _nmsnATarget="_top";
}


var _nmsnCobrand;
var _optusImgFolder = _spacURL + "/../..";

//Try and retrieve previous cookie if exists on this domain
_nmsnCobrand = Get_Cookie("brand");
setCookieValue();	// Get _cobr or _9msncobrandname value from query string 

if(_nmsnCobrand == undefined) //Still no cobrand, default to ninemsn.
{
	_nmsnCobrand = "ninemsn";
}
var timeToStore = new Date();
timeToStore.setTime(timeToStore.getTime() + (1000*60*60)); //expire after 1 hour
document.cookie = "brand="+_nmsnCobrand+"; expires="+timeToStore.toGMTString()+"; path=/"; //force cookie to be dropped in root of domain

//function gets the cookie, if it exists
function Get_Cookie(name)
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if((!start) && (name != document.cookie.substring(0, name.length)))
	{	
		return null;
	}
	if(start == -1)
	{
		return null;
	}
	var end = document.cookie.indexOf(";", len);
	if(end == -1)
	{
		end = document.cookie.length;
	}
	return unescape(document.cookie.substring(len, end));
}


function submit_nmsnsearch()
{
		var strInput;
		strInput = document.getElementById("hd_ms_input").value;
		window.location.href = "http://search.live.com/results.aspx?MKT=en-au&RS=CHECKED&FORM=ALDIST&q=" + strInput;
}

function checkEnter(e) //e is event object passed from function invocation
{
	var characterCode;  //literal character code will be stored in this variable

	if(e && e.which)
	{ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else
	{
		e = event;
		characterCode = e.keyCode ;//character code is contained in IE's keyCode property
	}

	if(characterCode == 13)
	{ //if generated character code is equal to ascii 13 (if enter key)
		return true ;
	}
	else
	{
		return false ;
	}
}

function reloadnmsnForm(e)
{
	if (checkEnter(e))
	{
		submit_nmsnsearch(this.form);
		return false;
	}

}

function reloadoptusForm(e)
{
	if (checkEnter(e))
	{
		submitOptuszooSearch(this.form);
		return false;
	}

}



function submitOptuszooSearch()
{
	
		var sType = document.getElementById("header_searchType");
		if(sType.value == "1")
		{
			window.location.href = "http://search.ninemsn.com.au/results.aspx?URL=http://search.ninemsn.com.au/results.aspx&FORM=ALDIST&CY=en-au&rf=1&RS=CHECKED&q=" + document.getElementById("header_searchInput").value;
					
		}
		else
		{
			document.getElementById("header_searchInput").value += sType.value;
			window.location.href = "http://search.ninemsn.com.au/results.aspx?URL=http://search.ninemsn.com.au/results.aspx&FORM=ALDIST&CY=en-au&RS=CHECKED&q=" + document.getElementById("header_searchInput").value;
		}

	return false;
}

function setCookieValue()

{
	try{
			var qs = window.top.location.href.split("?")[1]; //Query string portion of URL. Must be top level window if this is a frame.
			if(qs != undefined && qs != "")
			{
				var qspairs = qs.split("&");
				for(var i = 0; i < qspairs.length; i++)
				{
					var qsparam = qspairs[i].split("=");
					var cobr = qsparam[0].toLowerCase();
					
					// Get the cobrand value from the url if there is one and set _nmsnCobrand to the cobrand value
					if(cobr == "_9msncobrandname" || cobr == "_cobr")
					{
						if(qsparam[1])
						{
						_nmsnCobrand = qsparam[1].toLowerCase();
						}
					}
				}
	         }
		
		}
		catch(err)
		{
		//Do nothing. This error gets caused when header.js is running in an iframe and cannot run a window.top.location.href call.
		//If this error gets caught though it means that the Optus header may not appear when it should
		}

}