// Menu script

window.onerror = null;
var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
var NS4 = (bName == "Netscape" && bVer >= 4);
var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
var NS3 = (bName == "Netscape" && bVer < 4);
var IE3 = (bName == "Microsoft Internet Explorer" && bVer < 4);
var menuActive = 0
var menuOn = 0
var onLayer
var timeOn = null


// LAYER SWITCHING CODE
if (NS4 || IE4)
{
	if (navigator.appName == "Netscape")
	{
		layerStyleRef="layer.";
		layerRef="document.layers";
		styleSwitch="";
	}
	else
	{
 		layerStyleRef="layer.style.";
 		layerRef="document.all";
 		styleSwitch=".style";
 	}
}
 
// SHOW MENU
function showLayer(layerName)
{
	if (NS4 || IE4)
	{

		if (timeOn != null)
 		{
 			clearTimeout(timeOn)
			hideLayer(onLayer)
 		}
 		if (NS4 || IE4)
 		{
 			if ((!(document.all)) && (!(document.layers)))
				{
 					eval('document.getElementById("'+layerName+'").style.visibility="visible"');
 				}
 			else
 				{	
 					eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
				}
 		} 
 		onLayer = layerName
 	}
}

// HIDE MENU
function hideLayer(layerName)
{
	if (menuActive == 0)
	{
 		if (NS4 || IE4)
 		{
 			if ((!(document.all)) && (!(document.layers)))
				{
					//alert(eval('document.getElementById("'+layerName+'").style.visibility'));
 					eval('document.getElementById("'+layerName+'").style.visibility="hidden"');
 				}
 			else
 				{		
		 			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
		 			
		 		}
 		}
 	}
}

// TIMER FOR BUTTON MOUSE OUT
function btnTimer()
{
	timeOn = setTimeout("btnOut()",2000)
}

// BUTTON MOUSE OUT
function btnOut(layerName)
{
	if (menuActive == 0)
	{
 		hideLayer(onLayer)
 	}
}

// MENU MOUSE OVER 
function menuOver(itemName)
{
	clearTimeout(timeOn)
 	menuActive = 1
}

// MENU MOUSE OUT 
function menuOut(itemName)
{
	menuActive = 0 
 	timeOn = setTimeout("hideLayer(onLayer)", 400)
}

// Country/exchange dropdown

function regionChange(object) {
    if (object.options[object.selectedIndex].value == "aus") {
        top.location = '/index.asp';
    }
    else {
        top.location = '' + object.options[object.selectedIndex].value;
    }
}

// Automatic Iframe resize

function resizeIFrame(iframe) {   
    iframe.height = iframe.contentWindow.document.body.scrollHeight + 60 + "px";
};

// Bar rollover message

var statusDiv = "off";

function showFormElementsBar(type)
{		
							
							
	if(type == "bar" && statusDiv == "off")
	{
		statusDiv = "on";	
		document.getElementById("bar").style.display="block";
	}
	if(type == "bar2" && statusDiv == "on")
	{
		statusDiv = "off";	
		document.getElementById("bar").style.display="none";
	}
}


// Horizontal Nav

$(document).ready(function () {

    var timeout = 500;
    var closetimer = 0;
    var ddmenuitem = 0;

    function jsddm_open() {
        jsddm_canceltimer();
        jsddm_close();
        ddmenuitem = $(this).find('ul').css('visibility', 'visible');
    }

    function jsddm_close()
    { if (ddmenuitem) ddmenuitem.css('visibility', 'hidden'); }

    function jsddm_timer()
    { closetimer = window.setTimeout(jsddm_close, timeout); }

    function jsddm_canceltimer() {
        if (closetimer) {
            window.clearTimeout(closetimer);
            closetimer = null;
        } 
    }

    $(document).ready(function () {
        $('#jsddm > li').bind('mouseover', jsddm_open)
        $('#jsddm > li').bind('mouseout', jsddm_timer)
    });

    document.onclick = jsddm_close;
});

// Homepage Random Images

function getRand(onPage) {
    numArray = null;

    if (onPage == 'sidepic') {
        numArray = new Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17");
    }

    if (onPage == 'welcomepic1') {
        numArray = new Array("1", "10");
    }

    if (onPage == 'welcomepic2') {
        numArray = new Array("3", "4");
    }

    if (onPage == 'welcomepic3') {
        numArray = new Array("5", "6");
    }

    if (onPage == 'welcomepic4') {
        numArray = new Array("7", "8");
    }

    //randomly load an image, using the var randNum
    //maxNum is the highest numbered image within the images directory


    var maxNum = numArray.length;
    var randNum = (Math.floor(Math.random() * maxNum));

    randNum = numArray[randNum];

    return randNum;
}


function getfocus() {
    window.focus();
}

// Show tabs

$(document).ready(function () {

    // $('.tabs ul li:first').css('background-image', 'url(/images/tabBgOver.gif)');

    $('.tabs ul li').click(function () {
        $('.tabs ul li').css('background-image', 'url(/images/tabBg.gif)');
        $(this).css('background-image', 'url(/images/tabBgOver.gif)');
    });

    $('.confTabs ul li').click(function () {
        $('.confTabs ul li').css('background-image', 'url(/images/tabBg.gif)');
        $(this).css('background-image', 'url(/images/tabBgOver.gif)');
    });

    $('.confTabs ul li:first').css('background-image', 'url(/images/tabBgOver.gif)');

    $('.confTab3').css('display', 'none');

    // Homepage newsletter popout

    $('.newsletterRollover').mouseover(function () {
        $('.newsletterPop').toggle();
    });
    $('.newsletterRollover').mouseout(function () {
        $('.newsletterPop').toggle();
    });



});

    // Tabs and local storage

function showTab(section) {
    var displaySection = section;

    $('.tab1').hide();
    $('.tab2').hide();
    $('.tab3').hide();
    $('.tab4').hide();
    $('.tab5').hide();
    $('#lblStatus').hide();
    $('.adminMessageBox').hide();
    $(displaySection).show();
    window.localStorage.setItem("selectedtabindex", displaySection);
}


// Dropdowns //

$(document).ready(function () {
    $('.documentHeaderOpen').mouseover(function () {
        $(this).addClass("documentRollover");
    });

    $('.documentHeaderOpen').click(function () {
        $(this).next().children(".documentContent").slideToggle(180);
        $(this).toggleClass("documentMinus");
    });

    $('.expandAll').mouseover(function () {
        $(this).addClass("documentRollover");
    });

    var expandStatus = 1;

    $('.expandAll').click(function () {
        if (expandStatus == 1) {
            $(".documentContent").slideDown(180);
            $(".documentHeaderOpen").addClass("documentMinus");
            $(this).toggleClass("expandMinus");
            expandStatus = 2;
        }
        else {
            $(".documentContent").slideUp(180);
            $(".documentHeaderOpen").removeClass("documentMinus");
            $(this).toggleClass("expandMinus");
            expandStatus = 1;
        }
    });

    $(".documentContent TH:nth-child(1)").css("text-align", "left");

    $('.closeMessage').click(function () {
        $('.adminMessageBox').css('display', 'none');
    });

    // Collateral message options

    $('.collateralMessageBox').mouseover(function () {
        $(this).addClass("documentRollover");
    });

    $('.collateralMessageBox').click(function () {
        $(this).css('display', 'none');
    });

    $(window).resize(function () {
        $('.collateralMessageBox').css('display', 'none');
    });


    $('.buttonStyle').mouseover().css('cursor', 'pointer');

    // Newsletter

    $('.private_investor').css('display', 'block');
    $('.institutional_investor').css('display', 'none');
    $('.financial_advisor').css('display', 'none');

    $(".private").click(function () {
        $('.private_investor').slideDown(300);
        $('.institutional_investor').css('display', 'none');
        $('.financial_advisor').css('display', 'none');
    });

    $(".institutional").click(function () {
        $('.private_investor').css('display', 'none');
        $('.institutional_investor').slideDown(300);
        $('.financial_advisor').css('display', 'none');
    });

    $(".financial").click(function () {
        $('.private_investor').css('display', 'none');
        $('.institutional_investor').css('display', 'none');
        $('.financial_advisor').slideDown(300);
    });

    /* FAQs */

    $('.faqQuestion a').click(function () {
            $(this).toggleClass("selectedQuestion");
            $(this).next().children(".faqContent").slideToggle(180);
     });

});

function fileValidation(check,type,pos) {
    var position = pos + "px";
    var checkId = "#" + check;
    var fileType = type;
    var fileTypeCheck = "." + type;
    var inp = $(checkId).val();
    if (jQuery.trim(inp).length > 0 && (inp.indexOf(fileTypeCheck) !== -1)) {
        return true;
    }
    $('.adminMessageBox').css('top', position);
    
    var message = "Please browse for a valid " + fileType + " document.";
    showAdminMessage(message);
    return false;
}

// Admin message //

function showAdminMessage(message) {
    var messageText = message;
    $('.adminMessageBox').show("slide", { direction: "left" }, 300);
    $('.adminMessage').text(messageText);
}

// Collateral message //

function showCollateralMessage(message,pos) {
    var messageText = message;
    var position = pos + "px";
    var screenWidth = $(window).width();
    var itemWidth = $('.collateralMessageBox').width() + 90;
    var leftPos = ((screenWidth - itemWidth) / 2);
    $('.collateralMessageBox').css('left', leftPos);
    $('.collateralMessageBox').css('top', position);
    $('.collateralMessageBox').show("slide", { direction: "left" }, 500);
    $('.collateralMessage').text(messageText);
}

/*
    else if (radioSelection == "institutional_investor") {
        finCheck = 0;
        document.getElementById("private_investor").style.display = "none";
        document.getElementById("institutional_investor").style.display = "block";
        document.getElementById("financial_advisor").style.display = "none";
    }
    else if (radioSelection == "financial_advisor") {
        finCheck = 1;
        document.getElementById("private_investor").style.display = "none";
        document.getElementById("institutional_investor").style.display = "none";
        document.getElementById("financial_advisor").style.display = "block";
    }
}
*/

/* Bar popup */

var statusDiv = "off";

function showFormElementsBar(type) {


    if (type == "bar" && statusDiv == "off") {
        statusDiv = "on";
        document.getElementById("bar").style.display = "block";
    }
    if (type == "bar2" && statusDiv == "on") {
        statusDiv = "off";
        document.getElementById("bar").style.display = "none";
    }
}
