/*----------- general tools -----------------*/
function getRef(theDiv) {
	var ref;
	if (document.layers) {
		ref=document.layers[theDiv];
		}
	else if (document.all){
		eval("ref=document.all."+theDiv);
		}
	else {
		ref=document.getElementById(theDiv);
		}
	return(ref);
	}

function getStyle(sty,sheet) {
	var rules, i;
	if (typeof document.styleSheets[sheet].cssRules == 'object') {
		rules = document.styleSheets[sheet].cssRules;
	} else {
		rules = document.styleSheets[sheet].rules;
		}
	for(i=0;i<rules.length;i++) {
		if (typeof rules[i].selectorText == 'string') {
			if (rules[i].selectorText.toUpperCase() == sty.toUpperCase()) {
				return(rules[i]);
				}
			}
		}
	return(false);
	}

function getElementStyle(el,styleProp) {
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = window.getComputedStyle(x,null).getPropertyValue(styleProp);
	else var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
    }

function getMouse(mouseEvent) {
	var coord = new Object;
	if (typeof window.innerWidth == 'number') {
		coord.x = mouseEvent.pageX;
		coord.y = mouseEvent.pageY;
	} else {
		coord.x = event.clientX;
		coord.y = event.clientY + document.body.scrollTop;
		}
	return(new Coord(coord.x,coord.y,0,0));
	}

function Coord(x,y,width,height) {
	this.x = x;
	this.y = y;
	this.height = height;
	this.width = width;
	this.toString = function() {
		return("x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height);
		}
	}

function trimpx(value) {
    var mystring = "";
    if (!value) return(0);
    if (typeof value == 'string')
        mystring = value;
    else mystring = value.toString();
    if (mystring.indexOf("px") > 0)
	    return(parseFloat(mystring.substring(0,mystring.indexOf("px"))));
	else return parseFloat(mystring);
	}
	
function newImage(arg) {
	if (document.images) {
		var rslt = new Image();
		rslt.src = arg;
		return rslt;
		}
	}

function rolover(ref,state) {
    var suffix, prefix;
    if (ref.tagName.toLowerCase() == 'img') {
        suffix = ref.src.substring(ref.src.lastIndexOf('.'));
        prefix = ref.src.substring(0,ref.src.lastIndexOf('.'));
        if (state && ref.src.indexOf('-over') < 1)
            ref.src = prefix + '-over' + suffix;
        if (!state && ref.src.indexOf('-over') > 1)
            ref.src = ref.src.replace('-over','');
        }
    else {
        suffix = ref.style.filter.substring(ref.style.filter.lastIndexOf('.'));
        prefix = ref.style.filter.substring(0,ref.style.filter.lastIndexOf('.'));
        if (state && ref.style.filter.indexOf('-over') < 1)
            ref.style.filter = prefix + '-over' + suffix;
        if (!state && ref.style.filter.indexOf('-over') > 1)
            ref.style.filter = ref.style.filter.replace('-over','');
        }
    }

function rolover_bullet(ref,state,style) {
	var liItem = ref.parentNode;
	if (!liItem.style.listStyle)
		liItem.style.listStyle = getStyle(style,0).style.listStyle;
	if (state) liItem.style.listStyle = liItem.style.listStyle.replace(".gif","-over.gif");
	else liItem.style.listStyle = liItem.style.listStyle.replace("-over.gif",".gif");
	}

function in_array(val,arr) {
	if (typeof arr != "object") return(-1);
	for(i=0;i<arr.length;i++) {
		if (val.indexOf(arr[i]) > -1) return(i);
		}
	return(-1);
	}

var dropshadowstate=-1;
function dropshadowRender(ref) {
	if (typeof ref == "undefined") return;
	var skip = String("# span script input style select br").split(" ");
	var tag, i;
	if (typeof ref == "object")
		for (i=0;i<ref.childNodes.length;i++) {
			tag = ref.childNodes.item(i).nodeName.toLowerCase();
			if ((in_array(tag,skip) < 0))
				dropshadowRender(ref.childNodes.item(i));
			}
	if (ref.className.length > 8)
		if (ref.className.toLowerCase().indexOf("dropshadow") >= 0) {
			var shadow = ref.innerHTML;
			//if (shadow.indexOf("<img") > -1)
				//shadow = shadow.replace(/-shadow\.gif/gi,".gif");
			if (dropshadowstate < 1) {
			    dropshadowstate=1;
			    ref.innerHTML = "<span>&#160;"+shadow+"</span>&#160;"+ref.innerHTML;
			} else {			
			    ref.innerHTML = "<span>&#160;"+shadow+"</span>&#160;<img src=\"/common/images/category-left.gif\" alt=\"\"/>&#160;&#160;"+ref.innerHTML+"&#160;<img src=\"/common/images/category-right.gif\" alt=\"\"/>";
			    }
			}
	}

function getRand(range) {
	var num = Math.floor(Math.random() * range);
	return(num);
	}

function getMousePos(e) {
	mouse_pos = getMouse(e);
	}

function getunicode(e){
	var unicode=e.keyCode? e.keyCode : e.charCode
	return(unicode);
	}
	
function textSearch(searchtext) {
    if (searchtext.length > 0) {
        var urlstring = "/tx/search/search.html?t=" + URLEncode(searchtext) ;
        window.location.href = urlstring;
        }
    }

function AttachCSS(file) {
    var cssNode = document.createElement('link');
    cssNode.setAttribute('rel', 'stylesheet');
    cssNode.setAttribute('type', 'text/css');
    cssNode.setAttribute('href', file);
    document.getElementsByTagName('head')[0].appendChild(cssNode); 
    }

function emailwindow(id) {
   window.open("/concerts/emailfriend?id="+id,"","toolbar=no,scrollbars=yes,location=no,status=no,width=580,height=320,resizable=1")
}

/*pre-load left-nav bullet*/
img = newImage("/common/images/list_bullet-over.gif");

if (BrowserDetect.OS=='Mac') {
	if (BrowserDetect.browser == 'Safari') AttachCSS('/common/css/mac.safari.css');
	else AttachCSS('/common/css/mac.firefox.css');
	}

if (BrowserDetect.OS=='Linux') {
	AttachCSS('/common/css/linux.css');
	}

/*-----------------Rotating Promo JS------------*/
function GetAdContent(DivisionID,FilePath) {
    ret = BGPA.WV.Site.UI.services.RotatingPromo.GetAdContent(DivisionID, FilePath, SetAdContent, OnAdTimeOut, OnAdError);
    }
function OnAdTimeOut(arg) {
    //document.getElementById("Tip").InnerHTML = arg;
    }
function OnAdError(arg) {
    //document.getElementById("Tip").InnerHTML = arg;
    }
function SetAdContent(adXml) {
    var DivisionID = "";
    if (window.ActiveXObject) {
        adDoc=new ActiveXObject("Microsoft.XMLDOM");
        adDoc.async=false;
        adDoc.loadXML(adXml);
        DivisionID = adDoc.getElementsByTagName("adcontent")[0].attributes[0].value;
        document.getElementById(DivisionID).innerHTML = adDoc.getElementsByTagName("adcontent")[0].childNodes[0].nodeValue;
        }
    else if (document.implementation && document.implementation.createDocument) {
        var parser = new DOMParser();
        var doc = parser.parseFromString(adXml, "text/xml");
        adDoc = doc.documentElement;
        DivisionID = adDoc.attributes[0].value;
        document.getElementById(DivisionID).innerHTML = adDoc.childNodes[0].nodeValue;
        }
    else {
        //document.getElementById("Tip").InnerHTML = "Unfortunately your browser does not support the code required for Vault Tips";
        }
    }

function mojamsubmission() {
    var url = "/concerts/search?search=1";
    if (document.getElementById("citykey").checked) url += "&key=city";
    else if (document.getElementById("venuekey").checked) url += "&key=venue";
    else url += "&key=performer";
    url += "&value=" + escape(document.getElementById("searchtext").value);
//    document.getElementById("searchtext").value = "loading..."
    location.href = url;
}
