//$Id: menu.js,v 1.15 2009/05/31 08:20:16 jason Exp $

function menu_go(cat,desc,status,id,target,nxt,fids,limit) {
	var lmf = ks_main.left_menu;
	var check = lmf.Menu_style == "admin" ? true : false;
	var f=lmf.document.forms[0];

	if (! takeWin(check)) {
		return;
	}
	if (lmf.Menu_style == "admin") {
		f.action=CgiDir+'/'+cat; // destination for admin menu
		if ("revieword" == cat.substr(0, 9)) {
			if (typeof Review_ord_parms.selectUser != "undefined") {
				var rop = Review_ord_parms;
				f.selectUser.value=rop.selectUser;
				f.selectStatus.value=rop.selectStatus;
				f.selectCustNum.value=rop.selectCustNum;
				f.selectShipto.value=rop.selectShipto;
				f.selectCC.value=rop.selectCC;
				f.selectCity.value=rop.selectCity;
				f.selectState.value=rop.selectState;
				f.selectZip.value=rop.selectZip;
				f.showShipto.value=rop.showShipto;
				f.showCC.value=rop.showCC;
				f.showCity.value=rop.showCity;
				f.showState.value=rop.showState;
				f.showZip.value=rop.showZip;
				f.showDT.value=rop.showDT;
				f.showApprovals.value=rop.showApprovals;
				f.showImpIDs.value=rop.showImpIDs;
				f.startDate.value=rop.startDate;
				f.endDate.value=rop.endDate;
				f.mode.value=rop.mode;
				f.done1.value=rop.done1;
				f.show_mine.value=rop.show_mine;
				if (f.show_mine.value=="true") {
					f.show_mine.value=1;
				} else if (f.show_mine.value=="false") {
					f.show_mine.value="";
				}
			}
		}
	} else {
		LastCatPage.cat=cat;
		LastCatPage.desc=desc;
		LastCatPage.status=status;
		LastCatPage.id=id;
		LastCatPage.target=target;
		LastCatPage.nxt=nxt;
		LastCatPage.fids=fids;
		LastCatPage.limit=limit;
		LastCatPage.args="";
		f.cat_id.value = cat;
		f.desc.value = desc;
		f.status.value = status;
		f.id.value = id;
		f.level.value = nxt;
		f.fids.value = fids;
		f.limit.value = limit;

		if (target) {
			f.target = target;
			if (target == "left_menu") {
				f.action = CgiDir+'/'+lmf.Left_cgi;
			} else {
				f.action = CgiDir+'/'+lmf.Main_cgi;
			}
		}
	}
	f.submit();
}
function menu_show(menu_id,shuffle) {
	if (document.getElementById) {
		var j, j_id, k, k_id, id, id2 = "", mf, sv_on, sv_id, sv_id2 = "";
		var lmf = ks_main.left_menu;
		var doc = lmf.document;
		
		if (shuffle) {
			sv_on = sv_id = lmf.On_id;
			j = split_id(sv_on);
			if (j != -1) {
				sv_id = sv_on.substr(0,j);
				sv_id2 = sv_on.substr(j);
			}
			lmf.On_id = "";
			id = menu_id;
			j = split_id(menu_id);
			if (j != -1) {
				id = menu_id.substr(0,j);
				id2 = menu_id.substr(j);
			}
			for (j=0;;j++) {
				// do not close the menu if the expand_menu is turned on...
				j_id = "h"+j;
				if (! doc.getElementById(j_id)) {
					break;
				}
				if (j_id == id) { // this catalog or a section was clicked
					if (sv_id != id) {  // clicked a new catalog
						doc.getElementById(j_id).style.display = "block";
						lmf.On_id = id;
					} else { // catalog or section was on
						if (! sv_id2 && ! id2) { // didn't click a section but there was one on
							if (! lmf.expand[j]) {
								doc.getElementById(j_id).style.display = "none";
							}
							lmf.On_id = "";
						} else if (! sv_id2 && id2) {
							doc.getElementById(menu_id).style.display = "block";
							lmf.On_id = menu_id;
						} else if (sv_id2 && ! id2) {
							doc.getElementById(sv_on).style.display = "none";
							lmf.On_id = id;
						} else if (sv_id2 && id2) {
							doc.getElementById(sv_on).style.display = "none";
							if (sv_id2 != id2) {
								doc.getElementById(menu_id).style.display = "block";
								lmf.On_id = menu_id;
							} else {
								lmf.On_id = id;
							}
						}
					}
				} else if (! lmf.expand[j]) { // not the clicked catalog
					doc.getElementById(j_id).style.display = "none";
					for (k=0;;k++) {
						k_id = j_id+"i"+k;
						if (! doc.getElementById(k_id)) {
							break;
						}
						doc.getElementById(k_id).style.display = "none";
					}
				}
			}
		}
		if (doc.getElementById("menu-footer")) {
			mf=doc.getElementById("menu-footer");
			var mg = doc.getElementById("menu-guts")
			var m = doc.getElementById("menu");
			var wh = lmf.innerHeight;
			if (typeof wh == "undefined") {
				wh = lmf.frameElement.height;
			}
			var h = mg.offsetHeight+mf.offsetHeight;
			if (h <= wh) {  // both divs fit
				doc.body.scroll="no";
				doc.body.style.height=wh+"px";
				m.style.minHeight = wh+"px";
			} else {
				if (parseInt(doc.body.style.height) != h) {
					doc.body.style.height = h+"px";
					m.style.height = h+"px";
					doc.body.scroll="yes";
				}
			}
		}
	}
}
function split_id(id) {
	var k = -1;
	if (typeof(id) == "string") {
		k = id.search("i");
	}
	return k;
}
function set_focus() {
	var lmf = ks_main.left_menu;
	lmf.document.location.hash=lmf.Curr_anchor;
}
function stat(msg) {
	status=msg;
	return true;
}
function supplies_mini(items,top_text,bottom_text) {
	mini("/mini_supplies3.cgi",items,top_text,bottom_text)
}
function companystore_mini(items,top_text,bottom_text) {
	mini("/mini_companystore3.cgi",items,top_text,bottom_text)
}
function forms_mini(items,top_text,bottom_text) {
	mini("/mini_forms3.cgi",items,top_text,bottom_text)
}
function mini(script,items,top_text,bottom_text) {
	var which = reqfile ? Review : this;
	var url = CgiDir+script+"?key="+Key+";items="+items;
	url += ";top_text="+top_text+";bottom_text="+bottom_text;
	url += ";cust_id="+which.Subs_cust+";login="+login;
	url += ';pcat='+My_name+';ccat='+Hot_name+";set_qp="+Set_personal+";set_qc="+Set_company;
	ks_main.sub_main.location.href=url;
}
