function submitform() {
	document.form.submit()
}

function searchform() {
	document.searchform.submit()
}

function jumptopage(pg) {
	document.next.page.value=pg;
	document.next.submit()
}

function showwindow(thewidth,theheight,theurl) {
	if (!window.pdWindow) {
		pdWindow = window.open(theurl,"PopOpt","width=" + thewidth + ",height=" + theheight + ",toolbar=0,status=0,location=0,menubar=0,scrollbars=yes,resizable=0");
	} else {
		if (!pdWindow.closed) {
			pdWindow.close();
			pdWindow = window.open(theurl,"PopOpt","width=" + thewidth + ",height=" + theheight + ",toolbar=0,status=0,location=0,menubar=0,scrollbars=yes,resizable=0");
		} else {
			pdWindow = window.open(theurl,"PopOpt","width=" + thewidth + ",height=" + theheight + ",toolbar=0,status=0,location=0,menubar=0,scrollbars=yes,resizable=0");
		}
	}
}
	
function gcid(href) {
	var matches = href.match(/catid=([0-9]+)/i);
	
	if (matches != null && matches.length > 1) {
		var val = parseInt(matches[1]);
		
		if (!isNaN(val)) return val;
	}
	
	return -1;
}

function scat(id) {	
	if (id > -1) {
		$(".toplevelsub a").each(function(i) {			
			if (id == gcid($(this).attr("href"))) $(this).addClass("selected-sub-nav");
		});
	}
}

function scc() { scat(gcid(document.location.href)); }

function sp() {
	$(".breadcrumb-links > a").each(function(i) {
		var hrefId = gcid($(this).attr("href"));

		scat(hrefId);
	});
}

function gpid(ele) {
	if (ele.size() > 0) {
		var parid = ele.find("#SubnavigationOwner");
		
		if (parid.size() > 0) {
			var val = parseInt(parid.html());
			
			if (!isNaN(val)) return val
		}
	}
	
	return -1;
}

function isn() {
	var ele = $("#SiblingNavigation")
	var parid = gpid(ele);
	
	if (parid > -1) {
		$(".toplevelsub > a").each(function(i) {
			var hrefId = gcid($(this).attr("href"));

			if (parid == hrefId) {
				ele.remove();
				$(this).after(ele);
				ele.css("display", "block");
			}
		});
	}
}

function ipc() {
	var eles = $(".breadcrumb-links > a");
	
	if (eles.size() > 0) {
		eles.each(function(i) {
			dc(gcid($(this).attr("href")));
		});
	} else {
		dc(gcid(document.location.href));
	}
}

function dc(id) {
	if (id == 17) rn("fabrics");
	else if (id == 18) rn("products");
}

function rn(which) {
	var selected = (which == "fabrics") ? "first" : "last";
	
	$(".toplevelcat:" + selected).remove();
	$(".toplevelsub:" + selected).remove();
}

function initializeSelections() { ipc(); isn(); scc(); sp(); }