
///////////////////////////////////////////////////////////////////////////////////
// jQuery
///////////////////////////////////////////////////////////////////////////////////
$(document).ready(function(){
	formSagePay();
	ie6ReplaceImgs();
	prodRollovers();
});
function prodRollovers() {
	
	$(".moo_prod").mouseover(function(){
		$(this).css("background-image","url(/_imgs/furniture/moo_prod_bg_on.gif)");
		$(this).css("cursor","pointer");
	});
	$(".moo_prod").mouseout(function(){
		$(this).css("background-image","url(/_imgs/furniture/moo_prod_bg_off.gif)");
	});
	
	
	
	$(".moo_prod").each(function(){
		var url = $("p.moo_title a",this).attr("href");
		$(this).click(function(){
			$(location).attr('href',url);
		});
	});
	
	
}
function ie6ReplaceImgs() {
	// Replace the logo for ie6 (ie6 doesn't do transparent png's)
	if ($.browser.msie && $.browser.version==6) {
		$("#moo_logo").attr("src","/_imgs/furniture/logo.gif");
		$("#head_btn").attr("src","/_imgs/furniture/moo_searchbox_btn.gif");
		$("#form_head_search .head_q").css("background-image","url(/_imgs/furniture/moo_searchbox.gif)");
	}
}
function formSagePay() {
	// On load
	var val = $("#CardType").val();
	formSagePayShowHide(val);
	// On change
	$("#CardType").change(function () {
		var val = $(this).val();
		formSagePayShowHide(val);
	})
}
function formSagePayShowHide(val) {
	// Show if we have a value
	if (val!="") {
		$("#card_pic").fadeOut(1);
		$("#frm_fields").slideUp("fast");
		// Show/hide the from date
		if (val=="AMEX") { $("#frm_date_from").hide(); } else { $("#frm_date_from").show(); }
		// CVV number
		if (val=="AMEX") { $("#cvv").html("4"); } else { $("#cvv").html("3"); }
		// Show the options
		$("#frm_fields").slideDown("fast");
		$("#CardHolder").focus();
		// Card pic to show
		if (val=="AMEX") { $("#card_pic img").attr("src","/_imgs/basket/cc_front.jpg"); } else { $("#card_pic img").attr("src","/_imgs/basket/cc_back.jpg"); }
		$("#card_pic").fadeIn(2000);
	} else {
		// Hide if the value is nothing
		$("#card_pic").fadeOut(1);
		$("#frm_fields").slideUp("fast");
	}
}
///////////////////////////////////////////////////////////////////////////////////

// Add load events
// --------------------------------------------------------------------------------
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function () {
			oldonload();
			func();
		}
	}
}

// Menu function used for IE - proper browsers use CSS
// --------------------------------------------------------------------------------
sfHover = function() {
	var sfEls = document.getElementById("md_tabs").getElementsByTagName("li");
	
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"),"");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

// Menu function used for IE - proper browsers use CSS
// --------------------------------------------------------------------------------
sfHover2 = function() {
	
	var new_options = document.getElementById("new_options")
	if (!new_options) return false;
	
	var sfEls = new_options.getElementsByTagName("li");
	
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"),"");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover2);

// Check all tick boxes
// --------------------------------------------------------------------------------
function checkAll(field) {
	for (i = 0; i < field.length; i++) {
		field[i].checked = true;
	}
}
function uncheckAll(field) {
	for (i = 0; i < field.length; i++) {
		field[i].checked = false;
	}
}

// Add event handlers for cust price list
// --------------------------------------------------------------------------------
function md_custom_pricelist() {
	
	var md_cpl_sel_all = document.getElementById('md_cpl_sel_all');
	if (!md_cpl_sel_all) return false;
	
	var md_cpl_rem_all = document.getElementById('md_cpl_rem_all');
	if (!md_cpl_rem_all) return false;
	
	md_cpl_sel_all.onclick = function() {
		checkAll(document.md_cpl.CatID);
	}
	md_cpl_rem_all.onclick = function() {
		uncheckAll(document.md_cpl.CatID);
	}
	
}

addLoadEvent(md_custom_pricelist);

// Show or hide brand ranges when there are more than 20
// --------------------------------------------------------------------------------
function showHideBrandRanges() {
	var hide_these = document.getElementById("hide_these");
	var hide_link = document.getElementById("hide_link");
	if (hide_these && hide_link) {
		var a = document.createElement("a");
		var txt = document.createTextNode("Not all ranges are currently show - ");
		a.setAttribute("href","#");
		a.setAttribute("id","hide_link_a");
		a.innerHTML="View All Brand Ranges";
		hide_link.appendChild(txt);
		hide_link.appendChild(a);
		a.hide_link = hide_link;
		a.onclick = function() {
			hide_these.style.display="inline";
			this.hide_link.style.display="none";
			return false;
		}
	}
}

addLoadEvent(showHideBrandRanges);









