function subscribe_newsletter() {
	
	var name=$("#subscribe_name").attr('value');
	var email=$("#subscribe_email").attr('value');
	
	var fail=0; error="";
	
	if ((name=="") || (name=="Name")) { error+='- Please enter your Name\n'; fail=1; }
	if ((email=="") || (email=="Email")) { error+='- Please enter your Email Address\n'; fail=1; }
	if ((!isValidEmail(email)) && (email!="Enter your email address")) { error+='- Please enter correct Email Address\n'; fail=1; }

	if (fail==0) {
		var dataString="pg=subscribe&name=" + name + "&email=" + email;
		
		$.ajax({  
		   type: "GET",  
		   url: "index.php",  
		   data: dataString,  
		   success: function(msg) {  
				document.getElementById('newsletter').innerHTML='<span class="message-text">' + msg + '</span>';
		   }  
		});  
	} else {
		alert(error);
	}
     
}


function calendar(y,m) {
	var dataString="pg=calendar&y=" + y + "&m=" + m;
		
	$.ajax({  
	   type: "GET",  
	   url: "index.php",  
	   data: dataString,  
	   success: function(msg) {  
			$('#panel3').html(msg);
	   }  
	});  
	
}


function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function IsNumeric(val) {

    if (isNaN(parseFloat(val))) {
          return false;
     }

     return true
}


function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}


 function update_price(conid) {
	subtotal=0; subqty=0;
	for (i=1; i<=7; i++) {	
		if (IsNumeric($("#qty-" + conid + "-" +i).val())) {
			subqty+=parseInt($("#qty-" + conid + "-" +i).val());
			subtotal+=$("#qty-" + conid + "-" +i).val() * $("#qty-" + conid + "-" +i).attr("price");
		}
	}
	
	$("#total" + conid).html("= $" + CurrencyFormatted(subtotal));
	$("#subtotal" + conid).val(subtotal);
	$("#subqty" + conid).val(subqty);
	
	// sum up
	total=0; totalqty=parseInt(0);
	$(".subtotal").each(function() {
		num=$(this).val(); num++; num--;
		total+=num;
	});

	$(".subqty").each(function() {
		num=$(this).val(); num++; num--;
		totalqty+=num;
	});
	
	$("#qty").html("= " + totalqty);
	$("#amount").html("$ " + CurrencyFormatted(total));
	

 }
 
 
function update_donate() {
	donate1=0; donate2=0;
		
	if ($("#check1").attr("checked")==true) {
		
		if (IsNumeric($("#donate1").val())) {  donate1+=parseInt($("#donate1").val()); }
		if (IsNumeric($("#donate2").val())) { donate1+=parseInt($("#donate2").val()); }
		
	}
	

	if ($("#check2").attr("checked")==true) {
		
		if ($('input[name=donate3]:checked').val()!=0) { 
			donate2+=parseInt($('input[name=donate3]:checked').val() ); 
		} else {
			if (IsNumeric($("#donate4").val())) { donate2+=parseInt($("#donate4").val()); }	
		}
	}
	
	$("#number2").html("$ " + CurrencyFormatted(donate1));
	$("#number3").html("$ " + CurrencyFormatted(donate2));
	
	total=parseInt($("#total").val()) + parseInt(donate1) + parseInt(donate2) + parseInt(9);
	$("#number5").html("$ " + CurrencyFormatted(total));
	
				
}

function set_donate1() {
	if ($("#check1").attr("checked")==false) { 
		$("#donate1").addClass('disable'); $("#donate1").attr("readonly","readonly");
		$("#donate2").addClass('disable'); $("#donate2").attr("readonly","readonly");
	} else { 
		$("#donate1").removeClass('disable'); $("#donate1").attr("readonly","");
		$("#donate2").removeClass('disable'); $("#donate2").attr("readonly","");
	}
	
	update_donate();
}

function set_donate2() {
	if ($("#check2").attr("checked")==false) { 
		$("#opt1").attr('disabled','disabled'); $("#opt2").attr('disabled','disabled'); $("#opt3").attr('disabled','disabled'); $("#opt4").attr('disabled','disabled');
		$("#donate4").addClass('disable'); $("#donate4").attr("readonly","readonly");
	} else { 
		
		$("#opt1").removeAttr('disabled'); $("#opt2").removeAttr('disabled'); $("#opt3").removeAttr('disabled'); $("#opt4").removeAttr('disabled');
		$("#donate4").removeClass('disable'); $("#donate4").attr("readonly","");
	}
	
	update_donate();
}		

function check_season() {
	fourATickets = 0;
	fourBTickets = 0;
	eightATickets = 0;
	eightBTickets = 0;

	for(i=0; i<22; i++) {
		if($("#qty-" + i + "-4").val()) {
			fourATickets += ($("#qty-" + i + "-4").val() != 0 ? 1 : 0)
		}
	}

	for(i=0; i<22; i++) {
		if($("#qty-" + i + "-5").val()) {
			fourBTickets += ($("#qty-" + i + "-5").val() != 0 ? 1 : 0)
		}
	}

	for(i=0; i<22; i++) {
		if($("#qty-" + i + "-6").val()) {
			eightATickets += ($("#qty-" + i + "-6").val() != 0 ? 1 : 0)
		}
	}

	for(i=0; i<22; i++) {
		if($("#qty-" + i + "-7").val()) {
			eightBTickets += ($("#qty-" + i + "-7").val() != 0 ? 1 : 0)
		}
	}

	//alert(fourATickets + ", " + fourBTickets + ", " + eightATickets + ", " + eightBTickets)

	if((fourATickets > 0 && fourATickets < 8) ||
		(fourBTickets > 0 && fourBTickets < 8) ||
		(eightATickets > 0 && eightATickets < 8) ||
		(eightBTickets > 0 && eightBTickets < 8)) {
		return confirm("To take advantage of the benefits of the 2012 season membership please book a minimum of 4+ or 8+ concerts.");
	}
	return false;
}



















