function setProduct(productId) {
	//SET AND VALIDATE PERFCODE	
	
	if (document.getElementById('attr_' + productId) != null) {
		var productAttribute = document.getElementById('attr_' + productId).value;
	} else {
		var productAttribute = 0;
	}
	
	//SET AND VALIDATE QUANTITY
	if (document.getElementById('qty_' + productId).value > 0) {
		var productQuantity = document.getElementById('qty_' + productId).value;
		if (productQuantity > 10) {
			alert("We're sorry. The maximum number of items you can add to your cart at one time is 10.");
		} else {
			//SET PROMO CODE
			if (document.getElementById('promo_' + productId) != null) {
				var promoCode = document.getElementById('promo_' + productId).value.replace("(optional)","");
				
				window.location.href = "/article/the_basics/shop/index.html?productId=" + productId + "&productAttribute=" + productAttribute + "&productQuantity=" + productQuantity + "&promoCode=" + promoCode;
			} else {
				window.location.href = "/article/the_basics/shop/index.html?productId=" + productId + "&productAttribute=" + productAttribute + "&productQuantity=" + productQuantity;
			}
		}
	} else {
		alert("Please enter quantity");
	}
}

function buyButton(date,evt,loc) {

      var today = new Date();
      var onSale = new Date();
      var subDonorOnSale = new Date();

	  onSale.setFullYear(2009);
	  onSale.setDate(10);
	  onSale.setMonth(10);
	  onSale.setHours(11,0,0);
     
      subDonorOnSale.setFullYear(2009);
      subDonorOnSale.setDate(31);
      subDonorOnSale.setMonth(9);
      subDonorOnSale.setHours(11,0,0);

      var concert = new Date(date);
	  
	  if((evt == 13701) || (evt == 13702) || (evt == 13703) || (evt == 13704) || (evt == 13661) || (evt == 13538)) {
	  	  document.write("<h4>Free Event<\/h4><p>This concert is a part of Carnegie Hall&rsquo;s <a href=\"/article/explore_and_learn/art_neighborhood_concerts.html\" target=\"_blank\">Neighborhood Concert Series<\/a> and is free and open to the public.<\/p>");
	  } else if((today < concert) && (today > onSale)) {

      	  document.write("<h4>Buy Tickets<\/h4><p><a href=\"/SiteCode/Purchase/SeatSelectionPerformance.aspx?quantity=1&amp;quickBuy=false&amp;eventId="+evt+"\">Buy Now Online &rsaquo;<\/a><\/p>");

      } else if((today < onSale) && (today > subDonorOnSale)) {

          document.write("<h4>Buy Tickets<\/h4><p><a href=\"/SiteCode/MyCarnegieHall/SignIn.aspx?path=%2FSiteCode%2FPurchase%2FSeatSelectionPerformance.aspx%3Fquantity%3D1%26quickBuy%3Dfalse%26eventId%3D"+evt+"\">Subscribers and Donors&mdash;Sign in to buy now online &rsaquo;<\/a><\/p>");

      } else {
      	  
      	  document.write("<h4>Buy Tickets<\/h4><p>Tickets go on sale to the general public <strong>Tuesday, September 2, 2008 at 11 AM</strong><\/p>");
      	  
      }

}

function formatTitle(id,title) {
	title = title.replace(/\?/g," ");
	return title;
}

function previewText(html) {
	html = html.replace(/&amp;/gi,"&");
	html = html.replace(/&lt;/gi,"<");
	html = html.replace(/&gt;/gi,">");
	
	html = html.replace(/<p>/gi," ");
	html = html.replace(/<\/p>/gi," ");
	
	var words = html.split(" ");
	var preview = "";
	
	for(i=0; i<words.length && i<65; i++) {
		preview += words[i] + " ";
	}
	
	document.write(preview + " &hellip;");
}

function isText(html) {
	html = html.replace(/<[^>]+>/gi," ");
	html = html.replace(/^\s+|\s+$/g,"");
	
	if(html.length > 0) {
		return true;
	} else {
		return false;
	}
	
	return false;
}

function stripHTML(text,delimited,evt) {
	//GLOBAL HTML TAG REPLACE//
	//text = text.replace(/<[^>]+>/gi," ");
	
	/*text = text.replace(/<br>/gi," ");
	text = text.replace(/&lt;/gi,"<");
	text = text.replace(/&gt;/gi,">");*/
	
	if(isText(text) && delimited) {
		var lastChar = text.charAt(text.length-1);
		if((lastChar != ".") && (lastChar != ";") && (lastChar != "!") && (lastChar != "?")) {
			document.write(text + "; ");
		} else {
			document.write(text);
		}
	} else {
		document.write(text);
	}
}

function getStringMonth(month) {
	switch(month) {
		case '01': return "January/"; break;
		case '02': return "February/"; break;
		case '03': return "March/"; break;
		case '04': return "April/"; break;
		case '05': return "May/"; break;
		case '06': return "June/"; break;
		case '07': return "July/"; break;
		case '08': return "August/"; break;
		case '09': return "September/"; break;
		case '10': return "October/"; break;
		case '11': return "November/"; break;
		case '12': return "December/"; break;
	}
}

function getStringDay(day) {
	switch(day) {
		case 0: return "Sunday"; break;
		case 1: return "Monday"; break;
		case 2: return "Tuesday"; break;
		case 3: return "Wednesday"; break;
		case 4: return "Thursday"; break;
		case 5: return "Friday"; break;
		case 6: return "Saturday"; break;
	}
}

function getStringHours(hour) {
	t = hour.substring(0,2);
	m = hour.substring(2,5);
	if(m == ":00") {
		m = "";
	}
	if(t > 12) { 
		t = t - 12;
		return t + m + " PM";
	} else if(t == 12) {
		return t + m + " PM";
	} else {
		return t + m + " AM";
	}
}

function stripZero(dt) {
	if(dt.substring(0,1) == "0" && dt.length > 1) {
		return dt.substring(1,2);
	}
	else {
		return dt;
	}
}
	
function formatDate(evt) {
	var mo = evt.substring(0,2);
	var myMonth = getStringMonth(mo);
	var dt = evt.substring(3,5);
	myDate = new Date(dt + " " + myMonth.replace(/\//,'') + ", 2009");
	var t = getStringHours(evt.substring(11,16));
	if(t.indexOf(":00") > -1) {
		t = t.replace(":00","");
	}
	return getStringDay(myDate.getDay()) + ", <strong>" + myMonth.substring(0,myMonth.indexOf("/")) + " " + stripZero(dt) + "</strong> at " + t;
}

function getFormattedDate(evt) {
	var fdt = formatDate(evt);
	return fdt;
}

function setSecNav(div,title,date) {
	var el = document.getElementById(div);
	var enititle = title.replace(/<BR>/gim, ", ");
	
	if(date == "") {
		el.innerHTML = enititle;
	} else {
		el.innerHTML = enititle + ", " + date;
	}
}

function popUp(url, title, vars) {
	var pop = window.open(url, title, vars);
}

function popUPcenter(url, target, w, h) {
    putItCenter = window.open(url, target, 'width=' + w + ',height=' + h + ',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,left=' + ((screen.availWidth - w - 10) * .5) + ',top=' + ((screen.availHeight - h - 30) * .5));
	putItCenter.focus();
}

function popUpCenterResizable(url, target, w, h) {
    putItCenter = window.open(url, target, 'width=' + w + ',height=' + h + ',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=' + ((screen.availWidth - w - 10) * .5) + ',top=' + ((screen.availHeight - h - 30) * .5));
	putItCenter.focus();
}

function fshare(loc, title) {
	if(typeof urchinTracker == "function")  { urchinTracker("/outgoing/fshare/"); }
	popUp("http://www.facebook.com/sharer.php?u="+loc+"&t="+title,"fshare","toolbar=0,status=0,height=436,width=646,scrollbars=yes,resizable=yes");
}

function digg(loc, title, body) {
	if(typeof urchinTracker == "function")  { urchinTracker("/outgoing/digg/"); }
	popUp("http://digg.com/submit?phase=2&url="+loc+"&title="+title+"&bodytext="+body+"&topic=music","digg","toolbar=0,status=0,height=450,width=650,scrollbars=yes,resizable=yes");
}

function delicious(loc, title) {
	if(typeof urchinTracker == "function")  { urchinTracker("/outgoing/delicious/"); }
	popUp("http://del.icio.us/post?v=4&noui&jump=close&url="+loc+"&title="+title,"delicious","toolbar=0,status=0,height=400,width=700,scrollbars=yes,resizable=no")
}

function shareLinks(loc, title, body) {
	document.write("<div style='padding-top:10px;'><a href='javascript:{};' onclick='javascript:delicious(\""+loc+"\",\""+title+"\");' style='font-weight:normal;padding:2px 0 0 20px; height:16px; background:url(gfx/delicious.gif) no-repeat top left;'>save to del.icio.us &rsaquo;<\/a><\/div>" +
	"<div style='padding-top:10px;'><a href='javascript:{};' onclick='javascript:digg(\""+loc+"\",\""+title+"\",\""+body+"\");' style='font-weight:normal;padding:2px 0 0 20px; height:16px; background:url(gfx/digg.gif) no-repeat top left;'>digg it &rsaquo;<\/a><\/div>" +
	"<div style='padding-top:10px;'><a href='javascript:{};' onclick='javascript:fshare(\""+loc+"\",\""+title+"\");' style='font-weight:normal;padding:2px 0 0 20px; height:16px; background:url(gfx/fshare.gif) no-repeat top left;'>share on facebook &rsaquo;<\/a><\/div>");
}