function changePage(section, url) {
	var mast = top.mast.location.href;
	if (checkMast(mast, section)) {
		showContent(url);
	}
	else {
		url = fixURL(url);
		url = "/npms.jsp?section=" + section + "&url=" + url;
		top.location.href = url;
	}
}

function classifiedsSearch(subsection, category) {
	if (category == null) {
		category = subsection;
	}
	var mast = top.mast.location.href;
	if (checkMast(mast, subsection)) {
		showContent("/classifieds/classifieds-search.jsp?category=" + category + "&criteria=clear");
	}
	else {
		top.location.href = "/npms.jsp?section=classifieds&subsection=" + subsection + "&category=" + category + "&action=search&criteria=clear";
	}
}

function classifiedsSearchReturnURL(subsection, category) {
    var SLASH = "%2f";
    var QUESTION_MARK = "%3f";
    var AMPERSAND = "%26";
    var EQUALS = "%3d";
    
	if (category == null) {
		category = subsection;
	} // end if
    
    return SLASH + "npms.jsp"
           + QUESTION_MARK + "section" + EQUALS + "classifieds"
           + AMPERSAND + "subsection" + EQUALS + subsection
           + AMPERSAND + "category" + EQUALS + category
           + AMPERSAND + "action" + EQUALS + "search"
           + AMPERSAND + "criteria" + EQUALS + "clear";
} // end classifiedsSearchReturnURL()

function classifiedsIndex(category) {
	var mast = top.mast.location.href;
	if (checkMast(mast, subsection)) {
		showContent("/classifieds/classifieds-index.jsp?category=" + category);
	}
	else {
		top.location.href = "/npms.jsp?section=classifieds&category=" + category + "&action=index";
	}
}

function viewClassifiedsFolder(folderType) {
	var mast = top.mast.location.href;
	if (checkMast(mast, folderType)) {
		showContent("/classifieds/folder.jsp?type=" + folderType);
	}
	else {
		top.location.href = "/npms.jsp?section=classifieds&action=view-folder&category=" + folderType;
	}
}

function viewShoppingCart() {
	var mast = top.mast.location.href;
	if (checkMast(mast, "shop")) {
		showContent("/catalogues/shopping-cart.jsp");
	}
	else {
		top.location.href = "/npms.jsp?section=catalogues&action=view-basket";
	}
}

function cataloguesIndex(org) {
	var mast = top.mast.location.href;
	if (checkMast(mast, "shop")) {
		showContent("/catalogues/catalogues-index.jsp?org=" + org);
	}
	else {
		top.location.href = "/npms.jsp?section=catalogues&action=index&org=" + org;
	}
}

function cataloguesIndexByOrgID(orgID) {
	var mast = top.mast.location.href;
	if (checkMast(mast, "shop")) {
		showContent("/catalogues/catalogues-index.jsp?orgID=" + orgID);
	}
	else {
		top.location.href = "/npms.jsp?section=catalogues&action=index&orgID=" + orgID;
	}
}

function productSearch() {
	var mast = top.mast.location.href;
	if (checkMast(mast, "shop")) {
		showContent("/catalogues/product-search.jsp");
	}
	else {
		top.location.href = "/npms.jsp?section=catalogues&action=search";
	}
}

function showContent(URL) {
	top.content.location.href = URL;
}

function loadSearchProfile(category, profileID) {
	var mast = top.mast.location.href;
	if (checkMast(mast, category)) {
		showContent("/classifieds/load-search-profile.jsp?profileID=" + profileID);
	}
	else {
		top.location.href = "/npms.jsp?section=classifieds&category=" + category + "&action=load-profile&profileID=" + profileID;
	}
}

function checkMast(mastURL, category) {
	if (mastURL.search(category + ".html$") != -1 || mastURL.search(category + ".jsp$") != -1) {
		return true;
	}
}

function shopPage(URL) {
	var mast = top.mast.location.href;
	if (checkMast(mast, "shop")) {
		showContent(URL);
	}
	else {
		top.location.href = "/npms.jsp?section=catalogues&url=" + URL;
	}
}

function directorySearch(parms) {
	var url = "/directories/directory-search.jsp" + (parms != null ? "?" + parms : "");
	var mast = top.mast.location.href;
	if (checkMast(mast, "directories")) {
		showContent(url);
	}
	else {
		url = fixURL(url);
		top.location.href = "/npms.jsp?section=directories&url=" + url;
	}
}

function directoryBrowse(parms) {
	var url = "/directories/directory-browse.jsp?" + parms;
	var mast = top.mast.location.href;
	if (checkMast(mast, "directories")) {
		showContent(url);
	}
	else {
		url = fixURL(url);
		top.location.href = "/npms.jsp?section=directories&url=" + url;
	}
}

