﻿var currentLocation = window.location.href;
var partLocation = currentLocation.indexOf("?");
var eventLocation = currentLocation.substring(partLocation, 29);
var newSite = currentLocation.substring(0, partLocation);

var where = currentLocation.indexOf(".com");
var where2 = currentLocation.substring(0, where);
var where3 = currentLocation.indexOf(".gov");
var where4 = currentLocation.substring(0, where3);

var mainSite = "http://www.austrade.gov.au/";

function goOffice() {location.href = mainSite + $('select#office').val();}
function goOfficeMain() {location.href = mainSite + $('select#officesMain').val();}
function goWant() {location.href = mainSite + $('select#want').val();}
function goCountry() {location.href = mainSite + $('select#country').val();}
function goIndustry() {location.href = mainSite + $('select#industry').val();}
function goEventIndustry() {location.href = mainSite + "EventSearchAdv.aspx?Keywords=" + $('select#eventIndustry').val();}
function goEventState() {location.href = mainSite +"EventSearchAdv.aspx?Cou=12&Keywords=" + $('select#eventState').val();}
function goEventStateAwards() {location.href = "http://www.exportawards.gov.au/EventSearchAdv.aspx?Cou=12&Keywords=" + document.all.eventState.value;}
function goEventType() {location.href = mainSite + "EventSearchAdv.aspx?Keywords=" + $('select#eventType').val();}
function goEventSearch() {location.href = mainSite + "EventSearchAdv.aspx?Keywords=" + $('input#eventSearch').val();}
function goEventSearch2() {
    if (window.event.keyCode == 13)
    {
      location.href = mainSite + "EventSearchAdv.aspx?Keywords=" + $('input#eventSearch').val();
    }
}
function goBCA() {location.href = mainSite + $('select#BCAProg').val();}

function locateOffice() {
    location.href = mainSite + '/DealerLocator/locator.aspx?action=search&usercountry=' + $('.office-country-select select').val();
}

$('.backtotop a').html('<img border="0" align="absMiddle" longdesc="back to top of site" src="/images/UserUploadedImages/1374/backtotop.gif" alt="back to top of site" style="width: 9px; height: 9px;">back to top');

if (document.getElementById('mainWrapper')) {
    var maxResize = 3;
    var currentResize = 0;
    var ourText = $('#mainWrapper');
    var currFontSize = ourText.css('fontSize');
    var finalNum = parseFloat(currFontSize, 10);
    var stringEnding = currFontSize.slice(-2);
}

function biggerFont() {
    if (currentResize < maxResize) {
        finalNum *= 1.1;
        currentResize = currentResize+1;
    }
    ourText.css('fontSize', finalNum + stringEnding);    
}

function normalFont() {
    if (currentResize > 0) {
        finalNum /=1.1;
        currentResize = currentResize-1;
    }
    ourText.css('fontSize', finalNum + stringEnding);
}

if (document.getElementById("map"))
{
//call stall loading of google maps
setTimeout("mapload()", 2000);
}

$(document).ready(function() {

 if ($('form').is('.home')) { //if form class is home, apply hero slideshow widget settings 


	$('div.hero div.allsubItems > div').appendTo($('div.hero'));
    $('div.hero > div').addClass('mainItem');
	$('div.hero div.allsubItems').remove();
	$('div.hero h2').remove();

    $('.home #hero .container').prepend('<div id="nav">');

    $('.hero')
    .cycle({
		fx: 'fade',
                timeout: 12000,
                next:   '#next2',
                prev:   '#prev2',
                pager:  '#nav'
	});


$("#nav a").addClass(function(i){return "item" + (i + 1);}); //adds numbered classes to home slideshow nav to style thumbnail background images

   }

if ($('div').is('.RadMenu_CM477')) { //if this menu exists, do this
	
$("form#aspnetForm").addClass(" ");

}

});


if ($('body').is('.cm-article13582')) { //if body class is this, news and media centre, apply hero slideshow widget settings 
 
 	$('.topStory div.allsubItems > div').appendTo($('.topStory'));
    $('.topStory > div').addClass('mainItem');
	$('.topStory div.allsubItems').remove();
	$('.topStory h2').remove();
	
	$('.top-story').prepend('<div id="nav"><p>Featured Stories');

    $('.topStory')
    .cycle({
		fx: 'fade',
                timeout: 12000,
                next:   '#next1',
                prev:   '#prev1',
                pager:  '#nav'
	});
	
}

if ($('table').is('.clsPostcardBorder')) {   //if page is classic, load these other bits from tdcm pages


$("form#aspnetForm").addClass("site");
$('#TableTopNavBar').remove('');
$('#bannerTop').load('/About-Austrade/default.aspx #bannerTop .container');
$('#bannerBelow').load('/About-Austrade/default.aspx #bannerBelow .container');
$('#footerTop2').load('/About-Austrade/default.aspx #footerTop2 .container');
$('#footerBottom').load('/About-Austrade/default.aspx #footerBottom .container');

}


if ($('form').is('.local')) {   //if this is a local site, apply hero slideshow
    $('form.local #background')
    .cycle({
		fx: 'fade',
                timeout: 12000,
                next:   '#next',
                prev:   '#prev',
                pager:  '#nav'
	});

}

if ($('body').is('.cm-article10675')) {   //if this is the BCA landing page, apply hero slideshow
    $('form.bca #bcaSlide')
    .cycle({
		fx: 'fade',
                timeout: 12000,
                next:   '#next',
                prev:   '#prev',
                pager:  '#nav'
	});

}


if ($('div').is('#TBASDSupplierOuter')) {   //if the ASD left menu exists, get rid of the RHP
    $('#contentWrapper').addClass('Two noRHP');
	$('#contentWrapper').removeClass('Three');
	//$('#divASDSupplierNomArticleBottom').prependTo('#mainWrapper #contentWrapper');
	//$('#divASDSupplierNomArticleBottom').load('http://www.austrade.gov.au/ASD/default.aspx #LeftMenu');

}


 $('form.iriTool .radiobuttonlistDIV input').each(function () { //iri tool styling for checked buttons on page load
        $('form.iriTool .radiobuttonlistDIV input:checked').next('label').addClass("checked");
    });    

    $('form.iriTool .radiobuttonlistDIV input').click(function () { //iri tool styling for checked buttons on click
        $('form.iriTool .radiobuttonlistDIV input:not(:checked)').next('label').removeClass("checked");
        $('form.iriTool .radiobuttonlistDIV input:checked').next('label').addClass("checked");
    });    


$('.divRightQuestion, .divWrongQuestion').each(function(){ //converts broken characters from content organiser on report card page
    var $this = $(this);
    var t = $this.text();
    $this.html(t.replace('&lt','<').replace('&gt', '>'));
});


$("#IRIQuestionnaireContent input, #IRIQuestionnaireContent textarea").each(function () { //iri tooltips
    var tooltip= $(this).attr('title');
$(this).after('<div class="toolHover">')
$(this).next('div.toolHover').append(tooltip);
$("div.toolHover:empty").remove();
});

  $('#IRIQuestionnaireContent input[type="text"],  #IRIQuestionnaireContent textarea').addClass("idleField");
	$('#IRIQuestionnaireContent input[type="text"],  #IRIQuestionnaireContent textarea').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
$(this).next('div.toolHover').show("slow");
    });
 $('#IRIQuestionnaireContent input[type="text"],  #IRIQuestionnaireContent textarea').blur(function() {
    	$(this).removeClass("focusField").addClass("idleField");
       $(this).next('div.toolHover').hide("fast");
    });
    

$("form.iriTool input.btnFinish").click(function () { //content organiser validation
  if ($(".requiredDIV").is(":visible")) {
    $(".requiredDIV:visible").parent("label").addClass('pleaseChoose').before("<a name='empty'>&nbsp;</a>");
    $(".emptyChoice").remove();  
    $(".navigationDIV").append("<a class='emptyChoice' href='#empty'>*All questions are mandatory. Click here to complete your answer/s</a>");
   } else {
    
   }
 });

$("form.iriTool .radiobuttonlistDIV input").click(function () {
    $(this).parents(".userInputDIV").siblings('a').remove();
    $(this).parents(".userInputDIV").prev("label.pleaseChoose").removeClass('pleaseChoose');
 });


