/*----------- 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 (sheet < 0 || sheet >= document.styleSheets.length) return(false);
	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) {
	return (getElementStyleRaw(document.getElementById(el),styleProp));
    }

function getElementStyleRaw(x,styleProp) {
	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 getObjectPosition(ref) {
    return (getObjectPositionRaw(getRef(ref)));
    }
    
function getObjectPositionRaw(obj) {
    var location = new Coord(0,0,trimpx(getElementStyleRaw(obj,"width")),trimpx(getElementStyleRaw(obj,"height")));
    if( obj.offsetParent ) {
        for( location.x = 0, location.y = 0; obj; obj = obj.offsetParent ) {
            location.x += obj.offsetLeft;
            location.y += obj.offsetTop;
            }
        }
    return(location);
    }

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) {
    //need to debug this
	/*var liItem = ref.parentNode;
	if (!liItem.style.listStyle)
		liItem.style.listStyle = getStyle(style,1).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 giftsearch(type) {
  var urlstring;
 
    var obj = document.getElementById(type);
    if (obj != null) {
        if (obj.value.length > 0) {
            if (type=='datesearch') {
                urlstring = "/tx/search/search.html?t=" + URLEncode(obj.value) ;
            } else if ( type=='artistsearch') {
                urlstring = "/tx/search/search.html?t=" + URLEncode(obj.value) ;
            } else if ( type=='venuesearch') {
                urlstring = "/tx/search/search.html?t=" + URLEncode(obj.value) ;
            }
                if (urlstring != null && urlstring.length>0 ) {
                    window.location.href = urlstring;
                }
            }
        }
    }
function textSearch(searchtext, isUber, uberSearchHostname ) {
    if (searchtext.length > 0) {
        if (isUber) {
            var urlstring = "http://" + uberSearchHostname + "/search.aspx?t=" + URLEncode(searchtext) ;
             window.location.href = urlstring;
        } else {
            var urlstring = "/search/searchResults.aspx?q=" + URLEncode(searchtext) ;
            window.location.href = urlstring;
        }
    }
 }
function textSearchCategory(searchtext,categoryID) {
    var d = new Date();
    var urlstring = "";
    var Start, End, productType, productTypeIndex, productTypeRef;
    //Category search at very least
    
    if (categoryID == "CA")
        urlstring = "/fc/poster-art/CA.html";
    if (categoryID == "TS")
        urlstring = "/fc/apparel/TS.html";
    if (categoryID == "FP")
        urlstring = "/fc/fine-art-print/FP.html";
    if (categoryID == "BS")
        urlstring = "/fc/backstage/BS.html";
    if (categoryID == "VT")
        urlstring = "/fc/vintage-tickets/VT.html";
    if (categoryID == "PO")
        urlstring = "/fc/photography/PO.html";
    //Product types override categories
    productTypeRef = getRef('producttype');
    productTypeIndex = productTypeRef.selectedIndex;
    if (productTypeIndex > 0) {
        productType = productTypeRef.getElementsByTagName("option")[productTypeIndex].innerHTML.replace(' ','-').toLowerCase();
        productType = productType + '/' + productTypeRef.value;
        urlstring = "/fp/" + productType + ".html";
        }
    //get dates
    Start = document.getElementById('ctl00_main_content_CategorySearchObject_datefrom').value;
    if (Start.length < 1) Start = ""; //sr use blank as default date to avoid restricting by start date
    End = document.getElementById('ctl00_main_content_CategorySearchObject_dateto').value;
    if (End.length < 1) End = ''; //d.getFullYear() + 1;//sr use blank as default date to avoid restricting by end date
    //build final search
    if (searchtext.length > 0) {
        urlstring = "/tx/search/search.html" + urlstring + "?t=" + URLEncode(searchtext) + "&ys=" + Start + "&ye=" + End;
        window.location.href = urlstring;
        }
    }

function printpage() {
    var ref = getRef('printpage');
    ref.style.display='none';
    ref = getRef('main_header');
    ref.style.display='none';
    ref = getRef('leftnav');
    ref.style.display='none';
    ref = getRef('main_footer');
    ref.style.display='none';
    window.print();
    window.setTimeout('unprintpage();',1000);
    }

function unprintpage() {
    var ref = getRef("printpage");
    ref.style.display='block';
    ref = getRef('main_header');
    ref.style.display='block';
    ref = getRef('leftnav');
    ref.style.display='';
    ref = getRef('main_footer');
    ref.style.display='';
    }

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); 
    }

/*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');
	}

/*--------------Vault Tips JS---------------------*/
var tipDoc;
function vaulttips_next(tipnumber) {
    ret = BGPA.WV.Site.UI.services.VaultTips.GetTip(tipnumber, getTipInfo, OnTipTimeOut, OnTipError);
    }
function OnTipTimeOut(arg) {
    document.getElementById("Tip").InnerHTML = arg;
    }
function OnTipError(arg) {
    document.getElementById("Tip").InnerHTML = arg;
    }
function getTipInfo(tipXml) {
    if (window.ActiveXObject) {
        tipDoc=new ActiveXObject("Microsoft.XMLDOM");
        tipDoc.async=false;
        tipDoc.loadXML(tipXml);
        document.getElementById("Tip").innerHTML = tipDoc.getElementsByTagName("Tip")[0].childNodes[0].nodeValue;
        tipnumber = tipDoc.getElementsByTagName("Tip")[0].attributes.getNamedItem("TipID").nodeValue;
        }
    else if (document.implementation && document.implementation.createDocument) {
        var parser = new DOMParser();
        var doc = parser.parseFromString(tipXml, "text/xml");
        tipDoc = doc.documentElement;
        document.getElementById("Tip").innerHTML = tipDoc.childNodes[0].nodeValue;
        tipnumber = tipDoc.attributes.getNamedItem("TipID").nodeValue;
        }
    else {
        document.getElementById("Tip").InnerHTML = "Unfortunately your browser does not support the code required for Vault Tips";
        }
    }
    
    /*-----------------Session JS------------*/

    function IsCurrentCVSessionValidate() {
        var SessionID=GetCookie("CVTempSessionID")
       if (SessionID != null ) {
            return SessionID.length==36;
       } else {
            return false;
       }
       
       // alert(SessionID);
       // ret = BGPA.WV.Site.UI.services.Session.ValidateSessionID(SessionID) ; //, SetIsSessionValid,OnSessionTimeOut, OnSessionError);
       // alert(ret);
        }
    function SetIsSessionValid(val) {
       // alert(val);
    }
    function OnSessionTimeOut(arg) {}
    function OnSessionError(arg) {}



/*-----------------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";
        }
    }
    
/*--------More General Purpose Functions---------------*/
function URLEncode( plaintext ) {
	    // The Javascript escape and unescape functions	do not correspond
	    // with	what browsers actually do...
	    var	SAFECHARS =	"0123456789" +					// Numeric
					    "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					    "abcdefghijklmnopqrstuvwxyz" +
					    "-_.!~*'()";					// RFC2396 Mark	characters
	    var	HEX	= "0123456789ABCDEF";

	    //var plaintext	= document.URLForm.F1.value;
	    var	encoded	= "";
	    for	(var i = 0;	i <	plaintext.length; i++ )	{
		    var	ch = plaintext.charAt(i);
		    if (ch == "	") {
			    encoded	+= "+";				// x-www-urlencoded, rather	than %20
		    } else if (SAFECHARS.indexOf(ch) !=	-1)	{
			    encoded	+= ch;
		    } else {
			    var	charCode = ch.charCodeAt(0);
			    if (charCode > 255)	{
				    alert( "Unicode	Character '" 
						    + ch 
						    + "' cannot	be encoded using standard URL encoding.\n" +
						      "(URL	encoding only supports 8-bit characters.)\n" +
						      "A space (+) will	be substituted." );
				    encoded	+= "+";
			    } else {
				    encoded	+= "%";
				    encoded	+= HEX.charAt((charCode	>> 4) &	0xF);
				    encoded	+= HEX.charAt(charCode & 0xF);
			    }
		    }
	    } // for

	    //document.URLForm.F2.value	= encoded;
	    return encoded
    }
    
function setSessionCookie(name, value) {
    document.cookie =  escape(name) + '=' + escape(value)+';path=/';
    }
//below was taken from Customer service Contact Us page
function validateForm() {
	var isValid;
	isValid =  validateField("sendmail_email") && validateField("sendmail_message");
	if (!isValid) {
		alert('Please enter both your e-mail address and a message for customer service.');
	    }
	return isValid;
    }
function validateField(id) {
	var field;
	field = document.getElementById(id)
	if (field != null) {
		if(field.value.length > 0 ) { return true; }
		else { return false; }
	} else { return false; }
    }

var xmlDoc;
var popupwin = new Coord(0,0,0,0);
function checkoutHelp(type,origin) {
	popupwin = getObjectPositionRaw(origin);
	popupwin.x -= 12;
	popupwin.y--;
	/*if (type == "useage") popupwin.y += 55;
	if (type == "when") popupwin.y += 73;
	if (type == "privacy") popupwin.y += 90;
	if (type == "return") popupwin.y += 107;*/
    if (!xmlDoc) {
        if (typeof XMLHttpRequest != 'undefined') {
            try {
                xmlDoc = new XMLHttpRequest();
            } catch (e) {
                alert("Your browser is not supporting XMLHTTPRequest");
                xmlDoc = false;
                }
        } else {
            xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    xmlDoc.open("GET","/content/help/checkout-help.aspx?type="+type);
    xmlDoc.onreadystatechange = checkoutHelpPopulate;
    xmlDoc.send(null);
} 

function checkoutHelpPopulate()	{
    var ref = getRef("multipurpose");
    var reg = new RegExp("/.*<body>(.)</body>.*/gi");
    ref.style.left = popupwin.x + "px";
    ref.style.top = popupwin.y + "px";
    ref.style.display = "block";
    if (xmlDoc.readyState == 1) {
        ref.innerHTML = "<a class=\"close\" href=\"javascript:checkoutHelpClose();\">X</a><p>Loading...</p>";
        }
    if (xmlDoc.readyState == 4 && xmlDoc.status == 200) {
        var response = xmlDoc.responseText.replace(/.*<body>/,"").replace(/<\/body>.*/,"").replace(/<title>.*<\/title>/,"");
        ref.innerHTML = "<a class=\"close\" href=\"javascript:checkoutHelpClose();\">X</a>" + response;
        }
    }

function checkoutHelpClose() {
    var ref = getRef("multipurpose");
    ref.style.display = "none";
    }

/*concert vault functions here*/
function newconcerts_rolover(ref) {
    }

function newconcerts_click(ref) {
    var copyref = getRef("newconcerts_copy");
    var imageref = getRef("newconcerts_image");
    var playbutton = getRef("playbutton");
    copyref.innerHTML = "<i class=\"title\">" + ref.getElementsByTagName("img")[0].attributes.getNamedItem("title").value.split(" - ").join("</i><i class=\"title\">") + "</i>";
    copyref.innerHTML += "<p>" + ref.parentNode.getElementsByTagName("p")[0].innerHTML + "</p>";
    imageref.href = ref.href;
    playbutton.href = ref.href;
    imageref.getElementsByTagName("img")[0].src = ref.getElementsByTagName("img")[0].src;
    imageref.getElementsByTagName("img")[0].attributes.getNamedItem("title").value = ref.getElementsByTagName("img")[0].attributes.getNamedItem("title").value;
    imageref.getElementsByTagName("img")[0].attributes.getNamedItem("alt").value = ref.getElementsByTagName("img")[0].attributes.getNamedItem("alt").value;
    if (newconcerts_active) {
        newconcerts_active.parentNode.className = "noborder";
        }
    ref.parentNode.className = "bordered";
    newconcerts_active = ref;
    }

function yearsearch(ref) {
    var val = ref.getElementsByTagName("option")[ref.selectedIndex].value;
    if (val != "-") {
        location.href = "/dc/decade/" + val + ".html";
        }
    }

function RemoveWhiteSpace(value) {
    if (value != null) {
       return  value.replace(/\s+/,'');
    } else {
        return value;
    }
 }
 
 function radiobutton(ref) {

    if (ref.id == "search_specific" && document.getElementById("search_all").checked == true) {
        document.getElementById("search_all").checked = false;
	document.getElementById("search_specific").checked = true;

    } else if (ref.id == "search_all" && document.getElementById("search_specific").checked == true) {
	document.getElementById("search_specific").checked = false;
	document.getElementById("search_all").checked = true;

    }
 }
    
    
    
    
 // this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
function GetCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}				

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 findInputElement(tagid) {
    var inputElements = document.getElementsByTagName("input");
    var i;
    for(i=0;i<inputElements.length;i++)
         if (inputElements[i].id.indexOf(tagid) >= 0) { return(inputElements[i]); }
    return(inputElements[0]);
    }