/**
* Make a dummy window.console object if firebug is not installed.
* @return {void}
*/
function safeFirebug() {
	if (!('console' in window) || !('firebug' in window.console)) { // if Firebug is not installed
		var firebugFunctions = ['log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml', 'group', 'groupEnd', 'time', 'timeEnd', 'count', 'trace', 'profile', 'profileEnd'],
			console = window.console || {}; // use existing console object if any
		
		console.firebug = '0'; // add a dummy firebug version
		
		for(var i = 0, name, fc; i < firebugFunctions.length; ++i) {
			name = firebugFunctions[i];
			fc = console[name];
			if (!fc) { // if the method doesn't exist yet
				console[name] = function(){}; // assign a dummy function to it
				console[name].dummy = true; // put a marker to know that it's a dummy function
			} else if (!fc.apply) { // if the console method already exists but is a dummy object (probably IE8)
				switch(name) { // some common console methods can be wrapped inside a function to restore .apply()
					case 'log':
					case 'debug':
					case 'info':
					case 'error':
						console[name] = (function(oldFc){
							return function(){
								var args = Array.prototype.slice.call(arguments);
								return oldFc(args.join(' '));
							};
						})(fc);
				}
			}
		} // end of loop
		
		if (!console.log.dummy) { // if the console.log is not a dummy function, create copies of this function for other "log"-type methods
			for(var i=0, logMethods = ['debug', 'info', 'error'], name;
				i < logMethods.length; i++) {
				name = logMethods[i];
				if (console[name].dummy) {
					console[name] = console.log;
				}
			}
		}
		window.console = console;
	}
} // end of function safeFirebug()
safeFirebug();



// ********* RETURN form submit
isFunction = false;
submitterName = null;
validate=false;

function rtSubmit(e) {
	if(validate) {
		if(!e) {
			if(window.event) {
				e = window.event;
			} else {
				return;
			}
		}

		if( typeof e.which === 'number' ) {
		//NS 4, NS 6+, Mozilla 0.9+, Opera
			e = e.which;
		} else if( typeof e.keyCode === 'number' ) {
		//IE, NS 6+, Mozilla 0.9+
			e = e.keyCode;
		} else if( typeof e.charCode === 'number' ) {
		//also NS 6+, Mozilla 0.9+
			e = e.charCode;
		} else {
			return;
		}

		if (submitterName) {
			if(e === 13) {
				if(isFunction) {
					// execute js function
					if(submitterName.charAt(submitterName.length - 1) === ")") {
						eval(submitterName);
					}
				} else {
					// submit form
					eval("document.forms['" + submitterName + "'].submit");
				}
			}
		}
	}
}

document.onkeypress = rtSubmit;
// *********

function t(e){
	var oBj=document.getElementById(e);
	oBj.className = (oBj.className==='ac')? 'ina':'ac';
}
function m3(n){
   	var menu, arrowImg, par;

     	menu = document.getElementById("mnu" + n);
		par = document.getElementById("mpar" + n);
      // Determine if the menu is currently showing.
     	if (menu.style.display === 'block'){

        	// If it is showing, hide the menu and update the twisty image.
       	menu.style.display = 'none';
       	par.className = 'm3pD';
      }else{

      	// Hide all layers first.
       	var divs = document.getElementsByTagName("div");
			var anchs = document.getElementsByTagName("a");

       	for (var i = 0; i < divs.length; i++) {
					if (divs[i].id.indexOf("mnu") >= 0) {
						divs[i].style.display = 'none';
					}
       	}

       	for (var j = 0; j < anchs.length; j++) {
					if (anchs[j].id.indexOf("mpar") >= 0) {
						anchs[j].className = 'm3pD';
					}
				}

        	// Show the menus and update their twisty images.
       	i = 1;
       	while (n.length >= i) {
					menu = document.getElementById("mnu" + n.substring(0, i));
					par = document.getElementById("mpar" + n.substring(0, i));
					menu.style.display = "block";
					par.className = 'm3pA';
					i += 1;
				}
   	}
	}


// function to show and hide the menu
function updateMenu(n, loc, callingObj){

 var menu;

 menu = document.getElementById("mnu" + n);

 // If already showing then close menu 
 if(menu.style.display !== 'none') {
 
 	menu.style.display = 'none';
  	callingObj.className = 'm3pD'; //was m3pD

 } else {

 	// If not showing then display menu   
   	menu.style.display = 'block';
   	callingObj.className = 'm3pD';    

 	location.href = loc; 
 }


}

function toggleFAQ(which) {
	var oBj=document.getElementById(which + 'A');
	var oBj2=document.getElementById(which + 'T');
	if(oBj.style.display==='none'){
		oBj.style.display='';
		oBj2.firstChild.data='Hide Answer';
	} else {
		oBj.style.display='none';
		oBj2.firstChild.data='Show Answer';
	}
}

function getPrintWindowParams() {
	return "width=664,menubar=yes,status=yes,scrollbars=yes,resizable=yes,top=20,left=20";
}


// the following function for the global search is necessary for as form 
// would require being placed inside the div, however eWebEditPro strips 
// the form out and places it around the div

function searchSubmit() {
	if ((document.getElementById("QueryText").value==='') || (document.getElementById("QueryText").value==='Search...')) { alert('Please enter a search term.'); return; }
	var search_url = "/portal/site/oca/menuitem.43cc470fed4d9ee33109002b8c8ac7a0/?vgnextoid=0b116c499f632010VgnVCM100000c8a87c0aRCRD&Page=1&Paging=true&QuerySubmit=true";
	var query_text = "QueryText=" + escape(document.getElementById("QueryText").value);
	document.location.href = search_url + "&" + query_text;
}

// The following function is to be called from the primary nav as a fix to
// a bug within ie5. It is required as anchor tags on images are not registered
// if a float style is applied to the anchor tag.
function ie5PrimaryNavFix(objRef) {
	if (is_ie && 
		navigator.userAgent.indexOf("MSIE 5.01") !== -1 && 
		navigator.userAgent.toLowerCase().indexOf("mac") === -1) {
		document.location.href = objRef.href;
	}
}

//WT - 1.0.8c
function drop(tag,drop_class,selected) {
for (i = 0; i < document.getElementsByTagName(tag).length; i++)
	{
		var elem = document.getElementsByTagName(tag)[i];
		if ((elem.id !== selected) && (elem.className === drop_class))
		{
			elem.style.display = "none";
		}
		if ((elem.id === selected) && (elem.className === drop_class))
		{
			elem.style.display = "block";
		}
	}
}

function redirect(dest_url) {
if (dest_url) {
		// if ( dest_url.substring(0,8) !== "/portal/" ) { window.open(dest_url, "_blank"); }
		if ( (dest_url.indexOf('/portal/site/') === -1) && (dest_url.indexOf('my.optus.com.au') === -1) ) { window.open(dest_url, "_blank"); }
		else { window.open(dest_url, "_parent"); }
		}
}

// browser compatibility style changes
document.write("<style type=\"text/css\">");
// mac:
if(!is_ff && navigator.userAgent.toLowerCase().indexOf("mac") !== -1) {
	document.write("#section-header{float:left;}");
	document.write("#result-heading{clear:right;border:#ffffff solid 2px;width:589px;}");
	document.write("#home-region-d{height: 74px}");
	document.write("div.sec-space{height: 15px;}");
	document.write("#home-region-b-col1,#home-region-b-col2{height: 187px;}");
	if (is_ie) { // if it's IE on MacOS
		if(navigator.userAgent.indexOf("MSIE 5")!==-1) {
			document.write("#home-col-c,#home-region-e{width:151px;}");
			document.write("#global-qLinks select{width:155px;}");
			document.write("#global-search .go,#global-qLinks .go{position:static;}");
		}
		// Spacing between region A & Wholesale & Business
		if(navigator.userAgent.indexOf("MSIE 5.23")!==-1) {
			document.write("#home-region-d {height: 74px}");
			document.write("#home-region-d-inner1,#home-region-d-inner2{height:33px;}");
			document.write("div.sec-space {height: 15px;}");
		}
	}
	if (is_opera)  {
		document.write("#result-summary{overflow:auto;}");
		document.write("#home-region-d {height: 74px}");
	    document.write("#home-region-d-inner1,#home-region-d-inner2{height:33px;}");
	    document.write("div.sec-space {height: 15px;}");
	}
// ns 6-6.x:
} else if(is_nav && (navigator.vendorSub.substring(0,1) === "6")) {
	document.write("#content{float:none;display:table;}");
	document.write("#content-full{float:none;position:relative}");
	document.write("#content-full form{position:relative;}");
	document.write("#content-main, #content-main-full, #content-generic, #content-generic-full{display:table;}");
	document.write("#float-tank{float:none;background-color:#ffffff;}");
	document.write("#float-tank-inner{float:none;}");
	document.write("#ln{clear:none;}");
	//document.write("#control{display:table;}");
	document.write("#control{margin-bottom:10px}");
	document.write("#control div{display:table;left:-30px;}");
	document.write("#home-region-a-col4{height:148px;}");
	document.write("#logo{height:43px;}");
	document.write("#home-region-c-col2{height:92px;}");
	document.write("#home-region-d{height:75px;}");
	document.write("#home-region-e{height:223px;}");	
	if(navigator.vendorSub === "6.2.3") {
		document.write("#col-e{display:table;}");
		document.write("#home-region-d{height:76px;}");
		document.write("#home-region-d-inner1,#home-region-d-inner2{height:33px;}");
		document.write("#home-region-e{height:228px;}");
		document.write("div.sec-space {HEIGHT: 15px;}");
	}	
} else if(is_ie) { // if IE
	document.write("#home-region-d{height:73px;}");
	document.write("#home-region-d-inner1,#home-region-d-inner2{height:32px;}");
	// ie5
	if(navigator.userAgent.indexOf("MSIE 5")!==-1) {
		document.write("div.faq-question span.faq-question-label-full{width:460px;}");
		document.write("div.rhs-promo-border,div.highlight-border{width:138px;}");
		document.write("#global-qLinks,#global-search{padding-top:0px;font-size:11px;height:48px;vertical-align:middle;}");
	}
	// ie5.01
	if (navigator.userAgent.indexOf("MSIE 5.01")!==-1) {
		document.write("#float-tank{width:auto;}");
		document.write("#float-tank-inner{width:auto;}");
	}
	// ie7 - note that this is the same tweaks as FireFox :)
	if (navigator.userAgent.indexOf("MSIE 7.")!==-1) {
		document.write("#home-region-d{height: 74px}");
		document.write("#home-region-d-inner1,#home-region-d-inner2{height:33px;}");
		document.write("div.sec-space{height: 15px;}");
		document.write("#home-col-a{height: 225px;}");
		document.write("#home-region-b-col1,#home-region-b-col2{height: 187px;}");
	}
// Mozilla Firefox 1.0: Spacing between region A & Wholesale & Business
} else if (is_ff) {
	document.write("#home-region-d{height: 74px}");
	document.write("#home-region-d-inner1,#home-region-d-inner2{height:33px;}");
	document.write("div.sec-space{height: 15px;}");
	document.write("#home-col-a{height: 225px;}");
	document.write("#home-region-b-col1,#home-region-b-col2{height: 187px;}");
// Mozilla
} else if (is_moz) {
	document.write("div.faq-answer-rhs-active{border-top:1px solid #c8e6ea;clear:both;background-color:#FFF3BF;visibility:visible;display:block;border-left:1px solid #c8e6ea;border-right:1px solid #c8e6ea;padding:3px;width:441px}");
	document.write("#formStyle{display:block;font-size:11px;height:350px;width:728px;background-color:#dce6ec;border:#046684 solid 1px;padding:10px;margin-top:10px; margin-bottom:10px}");
	// Mozilla 1.1 and Mozilla 1.2
	if (navigator.userAgent.indexOf("1.1")!==-1 || navigator.userAgent.indexOf("1.2")!==-1) {
		document.write("#home-region-a-col4{height:148px;}");
		document.write("#home-region-c-col2{height:92px;}");
	}
// Netscape > 7
} else if (is_nav7up)  {
	document.write("div.faq-answer-rhs-active{border-top:1px solid #c8e6ea;clear:both;background-color:#FFF3BF;visibility:visible;display:block;border-left:1px solid #c8e6ea;border-right:1px solid #c8e6ea;padding:3px;width:442px}");
    document.write("#formStyle{display:block;font-size:11px;height:350px;width:728px;background-color:#dce6ec;border:#046684 solid 1px;padding:10px;margin-top:10px; margin-bottom:10px}");
    // Netscape 7 and Netscape 7.01 - Fix for: Optus Zoo & Give your business simplicity regions stretch outside the boundary
    if (navigator.userAgent.indexOf("7.0")!==-1 || navigator.userAgent.indexOf("7.01")!==-1) {
		document.write("#home-region-a-col4{height:148px;}");
		document.write("#home-region-c-col2{height:92px;}");
	}
	// Netscape 7.2: Spacing between region A & Wholesale & Business
	if (navigator.userAgent.indexOf("7.2")!==-1) {
		document.write("#home-region-d {height: 74px}");
		document.write("#home-region-d-inner1,#home-region-d-inner2{height:33px;}");
		document.write("div.sec-space {height: 15px;}");
	}

// Opera
} else if (is_opera)  {
	document.write("#result-summary{overflow:auto;}");
	document.write("#home-region-d {height: 74px}");
	document.write("#home-region-d-inner1,#home-region-d-inner2{height:33px;}");
	document.write("div.sec-space {height: 15px;}");
}

// not(ns 6-6.x):	
if(!(is_nav && (navigator.vendorSub.substring(0,1) === "6"))) {
	document.write("#search-content{float:left;}");
}

// Always display vertical scrollbar to prevent page shifting horizontally
document.write("html { min-height: 100%; margin-bottom: 1px; }");
document.write("</style>");

////////////////////////////////////////////////////////////////////////////////
// General Config object
////////////////////////////////////////////////////////////////////////////////
window.Config = {
	isProd: (/^(www)\.optus\.com\.au$/.test(location.hostname)) // detect if we're on PROD
};

////////////////////////////////////////////////////////////////////////////////
// getUrlParams
////////////////////////////////////////////////////////////////////////////////
if (!window.getUrlParams) {
	//////////////////////////////////////////////////////////////////////////////////
	/**
	* Function to analyse URL parameters and copy them into an Object
	* Sample: '?site=personal&channel=corporate&amp;government'
	* @param {String} url URL string
	* @param {Bool} ignoreCache Ignore the cache
	* @return {Object} Object representation of the parameters.
	* @example
	* {
	* 	'variable name': 'variable value'
	* }
	*/
	(function(){
		var cache = {};
		window.getUrlParams = function (url, ignoreCache) {
			var ret, tokens, token, separatorIndex, paramName, paramVal;
			
			if (!url) { // not defined
				url = document.location.search; // use document by default
				if (url && (url.charAt(0) === '?')) { // if the string starts by a '?'
					url = url.substr(1);
				}
			} else {
				url = (url + '').replace(/^[^\?]*\?/, ''); // cast to string and make sure to remove the initial beginning of the URL
			}
			
			if (url.length) {
				// check in cache
				ret = !ignoreCache && cache[url];
				if (!ret) { // if the cache is empty or is ignored
					ret = {};
					tokens = url.split(/[;&]/);
					tokensLength = tokens.length;
					for(var i=0; i < tokensLength; i++) {
						token = tokens[i];
						separatorIndex = token.indexOf('='); // get index of the '=' char
						
						// store param name
						paramName = decodeURIComponent( (separatorIndex !== -1)? token.substr(0, separatorIndex) : token );
						if (separatorIndex !== -1) { // if there's a param value
							paramVal = decodeURIComponent( token.substr(separatorIndex + 1) );
						} else {
							paramVal = '';
						}
						ret[paramName] = paramVal;
					}
					
					// store analysed data in cache
					cache[url] = ret;
				}
			} else {
				ret = {};
			}
			return ret;
		}; // end of function getUrlParams(url) 
	})();
}

////////////////////////////////////////////////////////////////////////////////
// includeScript function
////////////////////////////////////////////////////////////////////////////////
/**
* Include one or several javascript files
* @note Use this function after onready/onload. If you want to use it earlier, you should set the useDocumentWrite parameter.
* @param {Object} params Include one or several javascript files with these parameters.
* Ex: includeScript({
* 	url: 'url', // single URL of a script
* 	url: function(){}, // a function reference - it will be executed with eval without creating any script. This feature is useful to provide a callback function to run after calling some other script
* 	url: ['url1', 'url2', 'url3', callbackFunction], // list of script URLs to use for with these parameters, only used when useDocumentWrite === false
* 	useDocumentWrite: false, // use document.write instead of a DOM .appendChild()
* 	debug: false // activate debug console (need Firebug)
* });
* 
* Advanced example:
* includeScript(
* 		{
* 			url: [
* 				function() {
* 					console.info('a');
* 				},
* 				'dummy_script_1.js.php', // output: 1
* 				function() {
* 					console.info('b');
* 				},
* 				'dummy_script_2.js.php', // output: 2
* 				function() {
* 					console.info('c');
* 				},
* 				'dummy_script_3.js.php', // output: 3
* 				function() {
* 					console.info('d');
* 				}
* 			],
* 			useDocumentWrite: false,
* 			debug: true
* 		}
* 	);
* 	
* 	The final output would be: "a, 1, b, 2, c, 3, d".
* @param {String} params Include a javascript file with this given URL
* @param {Array} params List of parameters. Process each parameter set individually.
* Ex: 
* 	includeScript([params1, params2, params3]);
* 	
* 	is the equivalent of 
* 	
* 	includeScript(params1);
* 	includeScript(params2);
* 	includeScript(params3);
* @return {void}
*/
if (window.includeScript === undefined) {
	window.includeScript = function(params) {
		var scriptUrl, 
			useDocumentWrite = false,
			debug = false,
			isIncludingList = false;
		
		//DEBUG
		//console.debug('includeScript: params', params);
		
		if (params instanceof Array) { // if it's an array
			if (params.length) {
				scriptUrl = params;
			} else {
				return;
			}
		} else if (arguments.callee.isFunction(params)) { // if it is a function
			params.apply(window, []); // run the function
			return;
		} else if (params instanceof Object) { // if there's multiple parameters
			scriptUrl = params.url;
			debug = !!params.debug;
			useDocumentWrite = !!params.useDocumentWrite;
		} else if (typeof params === 'string') { // or there's just a script URL
			scriptUrl = params;
		}
		
		if (scriptUrl) { // if there's one or many urls
			//DEBUG
			if (debug) {
				console.log('includeScript(): useDocumentWrite=', useDocumentWrite);
			}
			if (!useDocumentWrite) { // if we don't use document.write()
				var includeNextScript, // callback function for the next script to include (if any)
					scriptSrc, // script source
					script; // script tag
				
				isIncludingList = scriptUrl instanceof Array;
				if (isIncludingList && (scriptUrl.length === 0)) { // if the array of URLs is empty
					return; // do nothing
				}
			
				if (isIncludingList) { // if including a list of scripts - then, scriptUrl is an Array of URLs (or function references)
					scriptSrc = scriptUrl[0]; // use here the first URL
					scriptUrl.shift(); // advance in the array of URLs
					
					includeNextScript = function() {
						includeScript(params); // reuse params (where the list of URLs has just been reduced by one item
					};
					
					if (arguments.callee.isFunction(scriptSrc)) { // if scriptSrc is a function
						scriptSrc.apply(window, []); // run this function
						
						if ($.browser.safari2) { // if it's safari 2
							window.setTimeout(function() { // run the next script asynchronously (it's prudent because Safari2 doesn't support many recursion levels)
								includeNextScript(); 
							}, 0);
						} else { // non-safari2 browser support much more recursion levels
							includeNextScript(); 
						}
						return;
					}
				} else { // else, just use the scriptUrl variable
					scriptSrc = scriptUrl;
				}
				
				//DEBUG
				if (debug) {
					console.log('includeScript(): ', scriptSrc);
				}
				
				script = document.createElement('script');
				script.src = scriptSrc;
				
				if (includeNextScript) { // if there's several scripts to include, attach the callback function
					if (document.all && !window.opera) { // if IE
						//DEBUG
						debug && console.log('setup script.onreadystatechange for', scriptUrl);
						script.onreadystatechange = function() {
							//DEBUG
							debug && console.log(scriptUrl, 'this.readyState', this.readyState);
							if ((this.readyState == 'loaded') || (this.readyState == 'complete')) {
								includeNextScript();
							}
						};
					} else { // FF, Safari, Opera support onload on a script
						script.onload = function() {
							includeNextScript();
						};
					}
				}
				
				document.getElementsByTagName('head')[0].appendChild(script); // append it to the head of document
			} else {
				document.write('<script type="text/javascript" src="' + scriptUrl + '"' + 
					//DEBUG
					(debug? 'onload="console.log(\'includeScript(): loaded\', \'' + scriptUrl + '\');"' : '') +
					'><\/script>');
			}
		} else {
			throw new Error('includeScript(): no script URL!');
		}
	}; // end of window.includeScript = function(params)
	/**
	* Returns true if the given argument is a function
	* @paran {mixed} fc Variable to test
	* @return {Boolean} True if it is a function
	*/
	includeScript.isFunction = function(fc) {
		return (window.jQuery && window.jQuery.isFunction(fc)) // use jQuery if possible
			||
			(!window.jQuery && (fc instanceof Function)); // simple function test
	}; // end of includeScript.isFunction = function(fc)
	
	// try to detect that the onload event has already been done
	// WARNING: this works only if this piece of code is run before the page has loaded
	// includeScript.isPageLoaded = false;
	// var trackLoadEvent = function() {
		// includeScript.isPageLoaded = true;
	// };
	// if (window.attachEvent) {
		// window.attachEvent('onload', trackLoadEvent);
	// } else if (window.addEventListener) {
		// window.addEventListener('DOMContentLoaded', trackLoadEvent, false); // try to do this at the earliest for browsers that support it
		// window.addEventListener('load', trackLoadEvent, false);
	// }
	// trackLoadEvent = undefined;
}

/**
  * SSL Entrust Security Seal
  * This function will change the domain parameter of the footer SSL link URL to match that of Personal, SMB or www.optus.com.au (default)
  * @company Optus
  * @author Angela Jusuf, David HAN SZE CHUEN
  * @creation 02/01/2009
  */
var sslEntrustSecuritySealConfig = {
	elementId: "footer_entrust",
	domainPatterns: {
		"personal.optus.com.au": "personal\\.optus\\.com\\.au$",
		"smb.optus.com.au": "smb\\.optus\\.com\\.au$",
		"optusbusiness.com.au" : "^(www\\.)?optusbusiness\\.com\\.au$", // This can match optusbusiness.com.au & www.optusbusiness.com.au
		"my.optus.com.au" : "my\\.optus\\.com\\.au",
		"www.optus.com.au": "\\.*" // the default wildcard pattern should always be in the last order
	},
	entrustURLPrefix: "https://www.entrust.net/customer/profile.cfm"
};

/** 
* Changed the current domain value to personal/smb/default 
*/
function modifySSLUrl() {
	var currentDomain = window.location.hostname,
		domainPatterns = sslEntrustSecuritySealConfig.domainPatterns,
		targetElement = document.getElementById && document.getElementById(sslEntrustSecuritySealConfig.elementId),
		regexp;
	
	if (targetElement) {
		for (var domain in domainPatterns) {
			regexp = new RegExp(domainPatterns[domain]);
			if (regexp.test(currentDomain)) {
				/* link the footer entrust to the entrust URL with the modified current domain value as the domain parameter */
				targetElement.setAttribute("href", sslEntrustSecuritySealConfig.entrustURLPrefix + "?domain=" + domain);
				break;
			}
		}
	}
} // end of function modifySSLUrl()

// register the modifySSLUrl() function in the onload
window.onload = function(oldFc) {
	return function() {
		if (oldFc) {
			oldFc.apply(this, arguments);
		}
		modifySSLUrl();
	};
}(window.onload);

