// browser sniffers

isw3c = (document.getElementById) ? true : false;
imgs = (document.images) ? true: false;
isExplorer = (navigator.appName.indexOf('Microsoft')!=-1) ? true : false;
isMac = (navigator.appVersion.indexOf('Mac')!=-1) ? true : false;
isSafari = (navigator.appVersion.indexOf('Safari')!=-1) ? true : false;

pg = '';

// shorthand for getting objects and images

function gObj(me) {
	if (isw3c) {
	return document.getElementById(me);
	}
}

function gImg(me) {
	if (imgs) {
	return document.images[me];
	}
}

// moving down on page after link

y_num = 0;

function getWai() {
	var wai = 0;
	if (window.pageYOffset > 0) {
		wai = window.pageYOffset;
	} else if (document.body.scrollTop > 0) {
		wai = document.body.scrollTop;
	} else if (document.documentElement.scrollTop > 0) {
		wai = document.documentElement.scrollTop;
	}
	return wai;
}

function scrollToWai() {
	if (y_num > 0) {
		window.scrollTo(0,y_num);
	}
}

// sub-menu functions

function subMenuOn(sm) {
	var menu_on = gObj(sm);
	menu_on.className = "toplink_on";
	var subdiv_on = gObj(sm + "_sub_menu");
	subdiv_on.style.visibility = "visible";
}

function subMenuOff(sm,cls) {
	var menu_off = gObj(sm);
	menu_off.className = cls;
	var subdiv_off = gObj(sm + "_sub_menu");
	subdiv_off.style.visibility = "hidden";
}

// main pg ingots

function hiLite(lk) {
	gObj('head_'+lk).className = "on";
	gObj('a_'+lk).className = "linkon";
	gObj('ing_'+lk).className = "ingot_on";
}

function hiLiteOff(lk) {
	gObj('head_'+lk).className = "none";
	gObj('a_'+lk).className = "none";
	gObj('ing_'+lk).className = "ingot";
}

function goTo(url) {
	window.location.href = url;
}

// div height setting to butt to bottom

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function setDivHeights() {  // accounts for all that absolute positioning; sets footer, pagediv and shadow
	if (isw3c) {
		var windowHeight = getWindowHeight();
		var main = gObj('pagediv');
		var mainTop = main.offsetTop;
		var shadow = gObj('shadow');
		var textdiv = gObj('textdiv');
		var textdivHeight = textdiv.offsetHeight;
		var textdivTop = textdiv.offsetTop;
		var leftmen = gObj('leftmenu');
		var leftmenHeight = leftmen.offsetHeight;
		var leftmenTop = leftmen.offsetTop;
		var leftmenBottom = (leftmenTop + leftmenHeight);
		var textdivBottom = (textdivTop + textdivHeight);
		var footer = gObj('footer_div');
		var footerHeight = footer.offsetHeight;
		var text_is_longer = (textdivBottom - footerHeight >= leftmenBottom) ? true : false;
		var pgDivHt = (text_is_longer) ? (textdivBottom - mainTop) : (leftmenBottom + footerHeight - mainTop);
		var pageHt = (windowHeight > pgDivHt) ? windowHeight : pgDivHt;
		main.style.height = (pageHt) + 'px';
		shadow.style.height = (pageHt -10) + 'px';
		if (!text_is_longer) {
			textdiv.style.height = (pgDivHt) + "px";
			footer.style.marginTop = (pgDivHt - textdivHeight) + "px";
		}
		if (pg == 'home') {
			doMoreLinks();
		}
	}
}

// end div height setting to butt to bottom

// popup window

function openPpWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

// show invoice / hide invoice 

function showInv() {
	var inv = gObj('invDiv');
	inv.style.visibility = 'visible';
}


function hideInv() {
	var inv = gObj('invDiv');
	inv.style.visibility = 'hidden';
}

// disable return key on select forms

function keyCheck (field, event) {
	var keyCode = event.keyCode ? event.keyCode : 
                event.which ? event.which : event.charCode;
	if (keyCode != 13 && keyCode != 3) {
		return true;
	} else {
		return false;
	}
}

// search and date selection forms

function doFormSub(thefrm,str) {
	var frm = eval("document.forms['"+thefrm+"']");
	if ((thefrm == "datesform")||(thefrm == "datesform1")) {
		if (str.indexOf("select") < 0) {
			frm.action += "date/";
			if (str.indexOf(" - ") > -1) {
				var sel_arr = str.split(" - ");
				frm.action += sel_arr[0] + "/" + sel_arr[1];
			} else {
				frm.action += str + "/" + str;
			}
			frm.submit();
		} 
	} else if (thefrm == "searchform") {
		var srchval = eval("frm." + str +".value");
		if (srchval != "") {
			frm.action += str + "/" + escape(srchval);
			frm.submit();
		} else {
			return false;
		}
	}
}

// clear search box

function cl(t) {
	if (t.value == 'band, artist, venue...') {
		t.value = '';
	}
	t.className = 'style98';
}

// show/hide more text functions

function deepCss(who, css) {  // cross-browser style sniffer (cool)
    var val = '', str = '';
    if (!who || who.style == undefined) return '';
    if (/\-/.test(css)) {
		str = css.replace(/\-[a-z]/g, function(w) {
			return w.charAt(1).toUpperCase() + w.substring(2);
		})
    }
    val = who.style[str];
    if (!val) {
		if (who.currentStyle) {
			val = who.currentStyle[str];
		} else {
			var dv = document.defaultView || window;
			if (dv && dv.getComputedStyle) {
				val = dv.getComputedStyle(who,'').getPropertyValue(css);
            }
        }
    }
    return (val) ? val : '';
}


// PSVA leftmenu letter pick

function pickLtr(choice) {
	var prv_ltr = false;
	var nxt_ltr = false;
	var nDiv = gObj('alphalist');
	var list_txt = nDiv.innerHTML;
	var alphabet = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
	if (choice == "other") {
		prv_ltr = false;
		nxt_ltr = "A";
	} else {
		var i;
		for (i = 0; i < 26; i++) {
			if (choice == alphabet[i]) {
				prv_ltr = alphabet[i];
				nxt_ltr = (choice == 'Z') ? false : alphabet[i+1];
				break;
			}
		}
	}
	prv_ind = (prv_ltr) ? list_txt.indexOf("<!--" + prv_ltr + "-->") : 0;
	nxt_ind = (nxt_ltr) ? list_txt.indexOf("<!--" + nxt_ltr + "-->") : list_txt.length;
	var p_arr = nDiv.getElementsByTagName("p");
	var j;
	var p_ind = 0;
	for (j = 0; j < p_arr.length; j++) { 
		para = p_arr.item(j);
		p_txt = para.firstChild.innerHTML;
		p_ind = list_txt.indexOf(p_txt, p_ind);
		if ((p_ind > prv_ind) && (p_ind < nxt_ind)) {
			para.style.display = 'block';
		} else {
			para.style.display = 'none';
		}
	}
	// highlight the appropriate letter choice
	var alph_p = gObj('alphas');
	var alph_arr = alph_p.getElementsByTagName("a");
	var k;
	for (k = 0; k < alph_arr.length; k++) {
		a_txt = alph_arr.item(k).innerHTML;
		if (a_txt == choice) {
			alph_arr.item(k).className = "on";
		} else {
			alph_arr.item(k).className = "none";
		}
	}
}

// The following more/less link thing works because all the elements inside the more div
// (p and h3) have the same line-height and padding-bottom.  Also, padding is 1/2 of line height.


function showHide(dv) { 
	var nDiv = gObj(dv);
	var lObj = gObj(dv+"_link");
	var mObj = gObj(dv+"_more");
	var sObj = gObj(dv+"_span");
	var lines = (dv == "more_0") ? 7 : 3;  // how many lines in reduced div
	var p = nDiv.getElementsByTagName("p").item(0);
	var lineHt = deepCss(p,"line-height");
	var linePdg = deepCss(p,"padding-bottom");
	var ht = parseInt(lineHt.replace("px",""));
	var pd = parseInt(linePdg.replace("px",""));
	if (lObj.innerHTML == "more...") { 
		nDiv.style.height = "auto";
		nDiv.style.overflow = "visible";
		lObj.innerHTML = "...less";
		if (sObj != null) {
			sObj.style.display = "inline";
		}
	} else {
		nDiv.style.height = (lines * ht) + "px";  // gets adjusted below
		nDiv.style.overflow = "hidden";
		lObj.innerHTML = "more...";
		if (sObj != null) {
			sObj.style.display = "none";
		}
	}
	setDivHeights();
}	

function isMore(dv) {
	var nDiv = gObj(dv);
	var p = nDiv.getElementsByTagName("p").item(0);
	var lineHt = deepCss(p,"line-height");
	var ht = parseInt(lineHt.replace("px",""));
	if (nDiv.scrollHeight > nDiv.offsetHeight + ht) {
		return true;
	}
	return false;
}

function doMoreLinks() {  
	var i;
	for (i = 0; i < document.getElementsByTagName("div").length; i++) {
		var divClass = document.getElementsByTagName("div").item(i).className;
		if (divClass == "more_div") {
			var nDiv = document.getElementsByTagName("div").item(i);
			var p = nDiv.getElementsByTagName("p").item(0);
			var lineHt = deepCss(p,"line-height");
			var linePdg = deepCss(p,"padding-bottom");
			var ht = parseInt(lineHt.replace("px",""));
			var pd = parseInt(linePdg.replace("px",""));
			var divId = nDiv.id;
			var lines = (divId == "more_0") ? 7 : 3;  // how many lines in reduced div 
			var moreId = divId + "_more";
			var morePara = gObj(moreId);
			var currStr = morePara.innerHTML;
			var linkStr = '<a href="javascript:showHide(\''+divId+'\');" id="'+divId+'_link">more...</a>';
			if (isMore(divId)) {
				var paraArr = new Array();
				var j;
				for (j=0; j < nDiv.getElementsByTagName("p").length; j++) {
					var para = nDiv.getElementsByTagName("p").item(j);
					if (para.offsetTop < nDiv.offsetHeight + nDiv.offsetTop) {
						paraArr.push(para);
					}
				}
				var paras = paraArr.length;
				nDiv.style.height = (divId == "more_0") ? ( ((lines - 1) * ht) + (paras * pd) ) + "px" : ((lines * ht) + ((paras - 1) * pd)) + "px";
				if (currStr.indexOf("javascript:showHide") == -1) {
					morePara.innerHTML = currStr + linkStr;
				}
			} else if (currStr.indexOf(linkStr) > -1) {
				morePara.innerHTML = currStr.replace(linkStr,"");
			}
		}
	}
}

window.onload = function() {
	setDivHeights();
}

window.onresize = function() {
	setDivHeights();
}

window.onscroll = function() {
	setDivHeights();
}


