// JavaScript Document



function addLoadEvent(func) {
 var oldonload = window.onload;
 if (typeof window.onload != 'function') {
 window.onload = func;
} else {
 window.onload = function() {
 oldonload();
 func();
 }
 }
}

function getObject(objectId) {
if (document.getElementById && document.getElementById(objectId)) {
 return document.getElementById(objectId);
} else if (document.all && document.all(objectId)) {
return document.all(objectId);
} else {
return false;
}
}


function calcSubTotal(input){
 if (input.value.match(/[^0-9]/g)) alert('Ticket quantities must be numeric.');
 var ticketPrice = input.parentNode.getElementsByTagName('span')[0].innerHTML.replace(/[^0-9.]/g, "");
 var subTotal = ticketPrice * input.value;
 input.parentNode.getElementsByTagName('span')[1].innerHTML = ' = ' + formatCurrency(subTotal);
calcTotal();
}

function calcTotal(){
 var orchestraGeneral = parseFloat(document.getElementById('orchestraGeneral').parentNode.getElementsByTagName('span')[1].innerHTML.replace(/[^0-9.]/g, ""));
 var orchestraSenior = parseFloat(document.getElementById('orchestraSenior').parentNode.getElementsByTagName('span')[1].innerHTML.replace(/[^0-9.]/g, ""));
 var orchestraStudent = parseFloat(document.getElementById('orchestraStudent').parentNode.getElementsByTagName('span')[1].innerHTML.replace(/[^0-9.]/g, ""));
 var orchestraChild = parseFloat(document.getElementById('orchestraChild').parentNode.getElementsByTagName('span')[1].innerHTML.replace(/[^0-9.]/g, ""));
 var mezzanineGeneral = parseFloat(document.getElementById('mezzanineGeneral').parentNode.getElementsByTagName('span')[1].innerHTML.replace(/[^0-9.]/g, ""));
 var mezzanineSenior = parseFloat(document.getElementById('mezzanineSenior').parentNode.getElementsByTagName('span')[1].innerHTML.replace(/[^0-9.]/g, ""));
 var mezzanineStudent = parseFloat(document.getElementById('mezzanineStudent').parentNode.getElementsByTagName('span')[1].innerHTML.replace(/[^0-9.]/g, ""));
 var mezzanineChild = parseFloat(document.getElementById('mezzanineChild').parentNode.getElementsByTagName('span')[1].innerHTML.replace(/[^0-9.]/g, ""));
 var shippingCharge = (document.getElementById('mailtickets').checked) ? 2 : 0;
 var creditCharge = (document.getElementById('paybycredit').checked) ? 3 : 0;
 var subtotal = orchestraGeneral + orchestraSenior + orchestraStudent + orchestraChild + mezzanineGeneral + mezzanineSenior + mezzanineStudent + mezzanineChild;
 var total = (subtotal != 0) ? orchestraGeneral + orchestraSenior + orchestraStudent + orchestraChild + mezzanineGeneral + mezzanineSenior + mezzanineStudent + mezzanineChild + shippingCharge + creditCharge : 0;
 document.getElementById('subtotalDisplay').innerHTML = (subtotal != 0) ? formatCurrency(subtotal) : "";
 document.getElementById('subtotal').value = subtotal;
 document.getElementById('totalDisplay').innerHTML = (subtotal != 0) ? formatCurrency(total) : "";
 document.getElementById('total').value = total;
}

function formatCurrency(num) {
var num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num)) {
num = "0";
}
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10) {
cents = "0" + cents;
}
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) { num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
}
return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function getMonth(year, month) {
var url = location.protocol + "//" + document.domain + "/event.php?mode=getmonthdisplay&month=" + month + "&year=" + year;
var fnObj = document.getElementById("calendarEvents");
loadXMLDoc(url, "displayMonth", fnObj);
}

