/*
	Copyright DTDigital         :: www.dtdigital.com.au ::
	Unauthorised modification / use is a criminal offence, and
	will be prosecuted to the fullest extent permitted by law.
	All Rights Reserved
*/

NAVarr = new Array("home", "stores", "range", "diy", "gifts", "sustainability", "services", "contact", "entersite");
if (document.images)
{
	for (var NAVitem in NAVarr)
	{ 
		 for (var NAVicount=0; NAVicount < 2; NAVicount++)
		 { 
				eval("b" + NAVarr[NAVitem] + NAVicount + " = new Image()");
				eval("b" + NAVarr[NAVitem] + NAVicount + ".src = 'assets/swap_" + NAVarr[NAVitem] + "_" + NAVicount + ".gif'");
		 } 
	} 
}

function BturnOn(imageName)
{
	if (document.images)
	{
		var imageNumber = "";
		if (arguments.length > 1) imageNumber = arguments[1];
		document [imageName + imageNumber].src = eval("b" + imageName + "1.src");
	}
}

function BturnOff(imageName)
{
	if (document.images)
	{
		var imageNumber = "";
		if (arguments.length > 1) imageNumber = arguments[1];
		document [imageName + imageNumber].src = eval("b" + imageName + "0.src");
	}
}

function BturnOnInput(obj,imageName)
{
	if (obj.src)
	{
		obj.src = eval("b" + imageName + "1.src");
	}
}

function BturnOffInput(obj,imageName)
{
	if (obj.src)
	{
		obj.src = eval("b" + imageName + "0.src");
	}
}

function ddRedirect(dd)
{
	if (dd.options[dd.selectedIndex].value != "") self.location = dd.options[dd.selectedIndex].value;
}


function ismaxlength(obj, maxlength)
{
	if (obj.value.length>maxlength)
	{
		obj.value=obj.value.substring(0,maxlength)
	}
}

function addQuantityToLink(link)
{
	var quantityValue = document.getElementById("ProductDetailQuantity").value
	
	return link.href + "&quantity=" + quantityValue;
}


//Online Catalogue
function openOnlineCataloguePopup()
{
	Width = 1000;
	Height = 680;
	TopPosn = screen.height ? (screen.height - Height) / 2 : 100;
	LeftPosn = screen.width ? (screen.width - Width) / 2 : 100;
	window.open("emag/bunnings/index.html?document=catalogue/" + getEmagRegion(), "_blank", "top="+TopPosn+",left="+LeftPosn+",width="+Width+",height="+Height+", resizable=yes");
}

		              
function getEmagRegion()
{
	if (window.emagRegion)
	{
		return emagRegion;
	}
	else 
	{
		return "catalogue";
	}
}


var _jQueryLoaded = (typeof(jQuery) == "function");

if (_jQueryLoaded)
{
	$(document).ready(function() {
		$("a.hideselectsinie6").mouseover(function() {
			$("select.hideselectinie6").css("visibility", "hidden");
		});

		$("a.hideselectsinie6").mouseout(function() {
			$("select.hideselectinie6").css("visibility", "visible");
		});
		
		// Applies tooltip functionality
		tooltip();

		$("#maincontent textarea").keypress(function(e) {
			if (e.which == 13) {
				$(this).val($(this).val() + "\n");
				return false;
			}
		});

		// Fixes flicker on nav in IE6.
		var isLocationActive = false;

		$(".hoverify").hover(function() {
			if ($(this).find("img:first").attr("src").match("_1")) {
				isLocationActive = true;
			} else {
				$(this).find("img:first").attr("src", ($(this).find("img").attr("src").replace("_0", "_1")));
			}
		}, function() {
			(isLocationActive) ? isLocationActive = false : $(this).find("img:first").attr("src", ($(this).find("img").attr("src").replace("_1", "_0")));
		});

		// Hide store feedback form items
		$("#checkbox_style6").hide();
		
		// Store feedback - Show/hide based on radio selected
		$(".radio01 input[type=radio]").click(function() {
			($(this).val() == "No") ? $("#checkbox_style6").show() : $("#checkbox_style6").hide();
		});

		// Store feedback - Show/hide required fields depending on checkbox
		$("input[@type=checkbox].checkbox01").click(function() {
			$(".required01").toggle();
		});
		
		//show/hide visacard/mastercard message
		$(".visacardholder").hide();
		$(".mastercardholder").hide();

		$(".search1_autocomplete").autocomplete(
			"WebServices/keywords.aspx",
			{
			    delay: 0,
			    minChars: 0,
			    maxItemsToShow: 10
			}
		);
		
	
		$(".creditcardtype").change(function() {

			if ($(this).val() == "Visa") {
				$(".visacardholder").show();
				$(".mastercardholder").hide();
			} else if ($(this).val() == "MasterCard") 
			{
				$(".mastercardholder").show();
				$(".visacardholder").hide();
			} else
			{
				$(".mastercardholder").hide();
				$(".visacardholder").hide();
			}
		});		
		
	});
}
	
	
// Simple tooltip script without the need for plugins
this.tooltip = function(){	
	/* CONFIG */		
		var xOffset = 0;
		var yOffset = 0;	
		// these 2 values are fallback values if the browser fails to determine the offset		
	/* END CONFIG */		
	
	// Glossary link tooltip
	$("a.tooltip").hover(function(e){											  
		xOffset = $(this).offset().top;
		yOffset = $(this).offset().left;
		this.t = this.title;
		this.title = "";	
		$(this).css({ position: "relative" });	
		
		$("body").append("<div id='tooltip'><div class='tooltip-top'>&nbsp;</div><div class='tooltip-content'><div class='tooltip-padding'><div class='container-info noborder'><h4>"+ this.t.split("::::")[0] + "</h4>" + this.t.split("::::")[1] + "</div></div></div><div class='tooltip-btm'>&nbsp;</div></div>");
		var tooltipHeight = $("#tooltip").height();
		$("#tooltip")
			.css({
				top: (xOffset-tooltipHeight) + "px",
				left: (yOffset) + "px"
			}).show();
	},function(){
		this.title = this.t;
		$("#tooltip").remove();
	})
};
	

	