// Launch links on the top of the page
$(document).ready(function(){
    $("a[href='#top']").click(function(event){
		//prevent the default action for the click event
		event.preventDefault();
		
		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:0}, 500);
	});
});
// Access credit rating button => /about-us/about-rural-bank/investor-information
$(document).ready(function(){
    $("input[name=access_credit_rating]").click(function(){
        if($("input[name=agree]").is(':checked')){
            window.location = "/about-us/about-rural-bank/investor-information/credit-rating";
        }
        else{
            alert("You must be or represent a 'wholesale client' to view this credit rating information.");
        }
    });
});
function linksOnTop() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if ((anchor.getAttribute("href")) && (anchor.getAttribute("rel") == "top")) 
		{
		  anchor.target = "_top";
		}
	}
}

function checkSessionCookie() {
		var urlCookieHelp	= "nocookie.htm";
		var urlLogon		= "https://bank.ruralbank.com.au/banking/RBLIBanking/";
		var name 		= "session";
		var value		= "test_value";
		
		//set session cookie
		document.cookie	= name + "=" + escape(value);

		//determine which url to open
		var url = getCookie(name) ? urlLogon : urlCookieHelp;

		window.open (url,"BendigoBank", "top=0,left=0,toolbar=0,menubar=yes,directories=no,scrollbars=yes,resizable=yes,status=yes,screenX=0,screenY=0,width=790,height=470,border=0,hotkeys=0");
}	 
	
// returns true if specified cookie exists
function getCookie(name) {
    var prefix = name + "=" ;
    var cookieStartIndex = document.cookie.indexOf(prefix);

    //return true if cookie exists
    return (cookieStartIndex != -1) ? true : false;
}

// Used on the About Us > FAQs page, jumps to selected FAQ Category
function goToSelectedFaq() {
	window.location = $('select#faq_category option:selected').val();
}

// Used to jump to selected News Archive
function jumpToArchive() {
	var yearValue = $('select#year option:selected').val();
	if (yearValue != "") {
	    var archive_url = "http://" + location.hostname + yearValue;
            window.location=archive_url;
            return false;
	}
	else {
	    alert("Please select a year");
	    return false;
	}
}

// Open PDFs in new window with ERB Header
function openPDF(pdf_file) {
    var file = "/pdf/open-pdf?pdf=" + pdf_file;
    if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iP[ao]d/i))) { 
     file = pdf_file;
    pageTracker._trackPageview(file);
    }
window.open(file,'MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes');
    return false;

}

// Closes PDF window
function closeme() {
	window.close();
}

// The large icons needs a pop-up confirmation message before proceeding
function doPop(pdf_file){
	var ht = 120;
	var wd = 590;
	var lf = (screen.width - wd)/2;
	var tp = (screen.height - ht)/2;
	var file = "/pdf/open-pdf-confirm?pdf=" + pdf_file;
	window.open(file,'MyWindow','width='+wd+',height='+ht+',toolbar=no,location=no,status=no,resizable=yes, left='+lf+', top='+tp+'');
}



//modifies banners to open links in new windows
$(document).ready(function() {
	$('#banner, #right_banner, div.agri_banner').find('a[rel=http]').attr('target', '_blank');
});
