/* ########################################################################### *
/* ***** TELSTRA WHOLESALE *************************************************** *
/* ########################################################################### *
 * ##### DOCUMENT NAME:  js.css
 * ##### DOCUMENT HISTORY:
 * ##### Original: 2007-07-10 (George Hiley, ECLIPSE) 
/* ########################################################################### */
//switch protocol - switches between http and https for form SSL requirements

//<![CDATA[
/* 03/04/08. Forcing it to www.telstrawholesale.com to avoid error screens. */

if (window.isSSL){
	if ((isSSL!=0)&& location.protocol != 'https:') {
		/* 16/04/08 - next line lets staging pages slip through the cracks */
		if ((location.host == 'www.staging.telstrawholesale.com.au')) {
			window.location= 'https://' + location.host + location.pathname + location.search			
		} else {
			window.location= 'https://' + 'www.telstrawholesale.com.au' + location.pathname + location.search
		}
	}
	else if ((isSSL=0) && location.protocol != 'http:') {
		window.location= 'http://' + location.host + location.pathname + location.search
	}
}
else if (!window.isSSL && location.protocol != 'http:'){
	window.location= 'http://' + location.host + location.pathname + location.search
}
else {
	// do nothing
}
//]]>



// Function: init()
// Purpose:  Main initialise function.
function init()
{
	$('input:image').css('cursor','pointer');
	$('a').filter('.newWindow').click(openWin);
	//init_sifr();
	init_navigation();	
	init_omniture();
}

// <navigation>

// Dynamic variable from back-end
var breadcrumbsHtmlArray = new Array();
var omnitureIdArray = new Array();
var activeNavId;

// Initialises main, left and breadcrumb navigation
function init_navigation()
{
	// Parse active item identifiers
	// Example: <body id="myActiveMainNavId_myActiveLeftNavId">
	var activeIds = document.body.id.split('_');
	
	// The body element's id attribute must have an underscore,
	// even if the activeLeftNavId parameter is not passed.
	// Otherwise, a duplicate id would exist on the page.
	
	// If it does not have an underscore then escape.
	if (activeIds.length == 1) return;
	
	var activeMainNavId = activeIds[0];
	
	if (activeIds[1] == '')
	{
		var activeLeftNavId = null;
		activeNavId = null;
	}
	else if (activeIds[1].indexOf('OMNI') > -1)
	{
	    var activeLeftNavId = null;
	    activeNavId = activeIds[1];
	}
	else
	{
		var activeLeftNavId = activeIds[1];
		activeNavId = null;
    }
	
	// Activate mainNav's style
	document.getElementById(activeMainNavId).className += ' active';
	channel = document.getElementById(activeMainNavId).innerHTML;
	
	if (activeLeftNavId != null)
	{
		// Activate leftNav's style
		var a = document.getElementById(activeLeftNavId);
		if (a == null)
		{
//		    alert('An element with ID: ' + activeLeftNavId + ' does not exist.');
		    return;
		}
		a.className += ' active';
		breadcrumbsHtmlArray[breadcrumbsHtmlArray.length] = a.innerHTML;
	}
	
	if (document.getElementById('leftNav'))
    {
	    // Hide all lists then reveal relevant lists.
	    var uls = document.getElementById('leftNav').getElementsByTagName('ul');
	    var firstUl = uls[0];
	    hideLists(firstUl);
    	
	    if (activeLeftNavId != null)
	    {
		    showLists(document.getElementById(activeLeftNavId));
		    omnitureIdArray[omnitureIdArray.length] = document.getElementById(activeLeftNavId).innerHTML;
	    }
	    else
		    firstUl.style.display = 'block';
	}
	
	// Render breadcrumbs
	if (activeLeftNavId != null)
	{
		breadcrumbsHtmlArray[breadcrumbsHtmlArray.length] = ' &#62; ';
	}
    if (activeNavId != null)
    {
        omnitureIdArray[omnitureIdArray.length] = document.getElementById(activeNavId).innerHTML;
    }	
	omnitureIdArray[omnitureIdArray.length] = document.getElementById(activeMainNavId).innerHTML;
	if (document.getElementById('breadcrumbs'))
	{
	    breadcrumbsHtmlArray[breadcrumbsHtmlArray.length] = getAnchorHtml(document.getElementById(activeMainNavId).innerHTML, document.getElementById(activeMainNavId).href);
	    breadcrumbsHtmlArray[breadcrumbsHtmlArray.length] = ' &#62; ';
	    breadcrumbsHtmlArray[breadcrumbsHtmlArray.length] = getAnchorHtml('Home', '/');
	    document.getElementById('breadcrumbs').innerHTML = breadcrumbsHtmlArray.reverse().join('');
	}

	omnitureId = omnitureIdArray.reverse();
}

// Hides the given list and its child lists recursively.
function hideLists(ul)
{
	// If the element is a list, hide it.
	if (ul.tagName == 'UL')
		ul.style.display = 'none';
	
	// Recursively traverse the list's elements.
	for (var i = 0; i < ul.childNodes.length; i++)
		hideLists(ul.childNodes[i]);
}

// Show the lists from the given element, upwards.
function showLists(fromElement)
{
	// If the bounding container has been reached...
	if (fromElement.parentNode.tagName == 'DIV')
	{
		// Show the container.
		fromElement.style.display = 'block';
		
		// Finish traversal.
		return;
	}
	// If the element is a list...
	else if (fromElement.tagName == 'UL')
	{
		// Show the list.
		fromElement.style.display = 'block';
		
		// Find the first link in list.
		var as = fromElement.parentNode.getElementsByTagName('a');
		var a = as[0];
		 
		// Active the link's style.
		a.className += ' active';
		
		// Add the link to the breadcrumbs trail.
		breadcrumbsHtmlArray[breadcrumbsHtmlArray.length] = ' &#62; ';
		breadcrumbsHtmlArray[breadcrumbsHtmlArray.length] = getAnchorHtml(a.innerHTML, a.href);
		omnitureIdArray[omnitureIdArray.length] = a.innerHTML;
	}

	else if (fromElement.tagName == 'A')
	{
		var uls = fromElement.parentNode.getElementsByTagName('UL');
		if (uls.length > 0)
			uls[0].style.display = 'block';
	}
	
	// Recursively traverse the elements's parent.
	showLists(fromElement.parentNode);
}

// Returns the HTML of an Anchor element.
function getAnchorHtml(text, href)
{
	return '<a href="' + href + '">' + text + '</a>';
}

// </navigation>

function openWin() {
	var nWinHeight = parseInt(screen.availHeight * .8) - 150;
	var nWinWidth = parseInt(screen.availWidth * .8);
	var nWinTop = parseInt((screen.availHeight/2)-(nWinHeight/2)) - 80;
	var nWinLeft = parseInt((screen.availWidth/2)-(nWinWidth/2));
	var nWindow = window.open(this.href, this.title, 'width='+nWinWidth+',height='+nWinHeight+',top='+nWinTop+',left='+nWinLeft+',location=yes,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes,status=yes');
	nWindow.focus();
	return false;
}

//search code

	function fnSubmit(varDomainName)
		{
			var strInpValue = document.findForm.inpSearch.value.replace(/^\s+/g, '').replace(/\s+$/g, '');
			if(strInpValue == '') {
					document.location.reload(true);
				}
				document.findForm.inpSearch.value = strInpValue;
				document.findForm.domainName.value = varDomainName;
				document.findForm.submit();
			}

function fnKeyPressSearch( domainName )
	{
		var strInpValue = document.findForm.inpSearch.value.replace(/^\s+/g, '').replace(/\s+$/g, '');
		if(strInpValue == '') {
			document.location.reload(true);
			return false;
		}
		document.findForm.inpSearch.value = strInpValue;
		document.findForm.domainName.value = varDomainName;
		document.findForm.submit();
		return true;
	}

/*
SiteCatalyst Code 
Copyright 1997-2005 Omniture, Inc. 
More info available at http://www.omniture.com
*/

function init_omniture()
{
	/* Override any s_code.js default settings here */
	s.currencyCode='AUD'
	s.linkInternalFilters='javascript:,'
	
	/* Populate Site Specific Variables */
	s.server = window.location.protocol + '//' + window.location.host;
	s.prop1 = 'TW';
	s.prop2 = 'TW';
	s.prop3 = 'TW';
	s.eVar1 = s.prop1;
	s.eVar2 = s.prop2;
	s.eVar3 = s.prop3;

	if (document.getElementById('leftNav') || (activeNavId != null))
	{
	    s.prop4 = omnitureIdArray[omnitureIdArray.length - 1];

	    for (var i = 0; i < omnitureIdArray; i++)
		    this['s.eVar' + (i + 4)] = omnitureIdArray[i];
	    s.hier1 = s.prop1 + '|' + s.prop2 + '|' + s.prop3 + '|' + omnitureIdArray.join('|');
	    if (s.hier1.substr(s.hier1.length - 1, 1) == '|') s.hier1 = s.hier1.substr(0, s.hier1.length - 1); // Fix for Safari
	    s.pageName = s.prop1 + ':' + s.prop2 + ':' + s.prop3 + ':' + omnitureIdArray.join(':');
	    if (s.pageName.substr(s.pageName.length - 1, 1) == ':') s.pageName = s.pageName.substr(0, s.pageName.length - 1); // Fix for Safari
    }
    else
    {
        s.hier1 = s.prop1 + '|' + s.prop2 + '|' + s.prop3
        s.pageName = s.prop1 + ':' + s.prop2 + ':' + s.prop3;
    }
    
    //alert('pageName: ' + s.pageName + "\n\n" + 'hier1: ' + s.hier1);
    
    void(s.t());
}

/* matt h 15/11 - start - End of SiteCatalyst Variables */

/* Site specific doPlugins functions */
function s_prePlugins(s) {
	/* this gets run before standard doPlugins routines */
}

function s_postPlugins(s) {
	/* this gets run after standard doPlugins routines */
	
}

/* matt h 15/11 end - End of SiteCatalyst Variables */

// Schedule events.
$(document).ready(init);