
var cartItems=0;var teamID;var cityID;function addCommas(nStr)
{nStr+='';x=nStr.split('.');x1=x[0];x2=x.length>1?'.'+x[1]:'';var rgx=/(\d+)(\d{3})/;while(rgx.test(x1)){x1=x1.replace(rgx,'$1'+','+'$2');}
return x1+x2;}
function addToCart(id,nme){var qty=$("#qty_"+nme+"-"+id).val();if(qty!=0){var cost=$("#indvCost_"+nme+"-"+id).val();var costid=$("#indvItem_"+nme+"-"+id).val();var catid=$("#ticketCategory_"+nme+"-"+id).val();cartItems++;var cartStr=id+"-"+qty+"-"+cost+"-"+catid+"-"+nme+"-"+costid+"-"+cartItems;var cartList=($.cookie('ord')==null)?cartStr:$.cookie('ord')+","+cartStr;$.cookie('ord',cartList,{expires:7,path:'/'});$("#list_"+nme+"-"+id).fadeOut(500,function(){$("#listHide_"+nme+"-"+id).fadeIn(500,function(){setTimeout("showItem('"+id+"','"+nme+"');",2000);$("#bundlelist").append(buildCartItem(id,qty,cost,catid,nme));tallyCartTotal();});});}}
function openCart(){$("#checkoutButton").show();$("#bundletotal").show();$("#bundleimage").hide();}
function closeCart(){$.cookie('ord',null,{path:'/'});$("#checkoutButton").hide();$("#bundletotal").hide();$("#bundleimage").show();}
function removeFromCart(cartid){$("#bundleItem-"+cartid).remove();var cartList=$.cookie("ord").split(",");for(var i in cartList){var cartNode=cartList[i].split("-");if(cartNode[6]==cartid){cartList.splice(i,1);break;}}
tallyCartTotal();cartItems--;if(cartItems==0){closeCart();}else{$.cookie('ord',cartList,{expires:7,path:'/'});}}
function tallyCartTotal(){openCart();var tot=0;$("span[id='bundleSubTotal']").each(function(){subTot=($(this).text().toString());subTot=subTot.replace(",","")
tot=tot+Number(subTot);});tot=Number(tot).toFixed(2);$("#bundletotal").html("<font class='bold'>TOTAL:</font>&nbsp;&nbsp;USD "+addCommas(tot));}
function buildCartItem(id,qty,cost,catid,nme){var str;cost=Number(cost*qty).toFixed(2);cost=addCommas(cost);switch(nme){case"match":str="<div id='bundleItem-"+cartItems+"'>";str=str+"<li id='bundlelist_matchno'><font class='bold'>"+qty+" x MATCH "+id.slice(1,id.length)+":</font></li>";str=str+"<li id='bundlelist_catno'>Cat. "+catid+"</li>";str=str+"<li id='bundlelist_price'>USD <span id='bundleSubTotal'>"+cost+"</span></li>";str=str+"<li id='bundlelist_delete'>";str=str+"<a href='javascript:;' onClick='removeFromCart("+cartItems+");' title='Delete'>";str=str+"<img src='"+path+"images/buttons/delete.jpg' border='0' width='17' height='16' alt='Delete' /></a></li></div>";break;case"tst":switch(id){case"p1":case"s1":id=3;break;case"p2":case"s2":id=5;break;case"p3":case"s3":id=7;break;case"p4":case"s4":id="Final";break;}
str="<div id='bundleItem-"+cartItems+"'>"
str=str+"<li id='bundlelist_matchno'><font class='bold'>"+qty+" x TST "+id+":</font></li>"
str=str+"<li id='bundlelist_catno'>Cat. "+catid+"</li>"
str=str+"<li id='bundlelist_price'>USD <span id='bundleSubTotal'>"+cost+"</span></li>"
str=str+"<li id='bundlelist_delete'>"
str=str+"<a href='javascript:;' onClick='removeFromCart("+cartItems+");' title='Delete'>"
str=str+"<img src='"+path+"images/buttons/delete.jpg' border='0' width='17' height='16' alt='Delete' /></a></li></div>"
break;case"finals":str="<div id='bundleItem-"+cartItems+"'>"
str=str+"<li id='bundlelist_matchno'><font class='bold'>"+qty+" x FINALS:</font></li>"
str=str+"<li id='bundlelist_catno'>Cat. "+catid+"</li>"
str=str+"<li id='bundlelist_price'>USD <span id='bundleSubTotal'>"+cost+"</span></li>"
str=str+"<li id='bundlelist_delete'>"
str=str+"<a href='javascript:;' onClick='removeFromCart("+cartItems+");' title='Delete'>"
str=str+"<img src='"+path+"images/buttons/delete.jpg' border='0' width='17' height='16' alt='Delete' /></a></li></div>"
break;case"pack":str="<div id='bundleItem-"+cartItems+"'>"
str=str+"<li id='bundlelist_matchno'><font class='bold'>"+qty+" x PACKAGE</font></li>"
str=str+"<li id='bundlelist_catno'>&nbsp;</li>"
str=str+"<li id='bundlelist_price'>USD <span id='bundleSubTotal'>"+cost+"</span></li>"
str=str+"<li id='bundlelist_delete'>"
str=str+"<a href='javascript:;' onClick='removeFromCart("+cartItems+");' title='Delete'>"
str=str+"<img src='"+path+"images/buttons/delete.jpg' border='0' width='17' height='16' alt='Delete' /></a></li></div>"
break;case"act":str="<div id='bundleItem-"+cartItems+"'>"
str=str+"<li id='bundlelist_matchno'><font class='bold'>"+qty+" x Activity</font></li>"
str=str+"<li id='bundlelist_catno'>&nbsp;</li>"
str=str+"<li id='bundlelist_price'>USD <span id='bundleSubTotal'>"+cost+"</span></li>"
str=str+"<li id='bundlelist_delete'>"
str=str+"<a href='javascript:;' onClick='removeFromCart("+cartItems+");' title='Delete'>"
str=str+"<img src='"+path+"images/buttons/delete.jpg' border='0' width='17' height='16' alt='Delete' /></a></li></div>"
break;}
return str;}
function initCart(){cartItems=0;if($.cookie("ord")){var cartList=$.cookie("ord").split(",");for(var i in cartList){cartItems++;var cartNode=cartList[i].split("-");$("#bundlelist").append(buildCartItem(cartNode[0],cartNode[1],cartNode[2],cartNode[3],cartNode[4]));tallyCartTotal();}}else{closeCart();}}
function showItem(id,nme){$("#listHide_"+nme+"-"+id).fadeOut(500,function(){$("#list_"+nme+"-"+id).fadeIn(500);});}
function updateItemCost(id,catid,nme){var idTosend=id.slice(1,id.length);$("#cost_"+nme+"-"+id).html("updating...");$.get("../inc/ajax.costBy"+nme+".php",{teamid:teamID,id:idTosend,catid:catid},function(data){var costid=0;var cost=0;var subTot=0;cost=data.slice(0,data.indexOf("-"));costid=data.slice(data.indexOf("-")+1,data.length);subTot=(($("#qty_"+nme+"-"+id).val())*(cost));subTot=(subTot.toString()).replace(",","");subTot=Number(subTot).toFixed(2);$("#indvItem_"+nme+"-"+id).val(costid);$("#indvCost_"+nme+"-"+id).val(cost);$("#cost_"+nme+"-"+id).html("USD "+addCommas(subTot));if(cost==0){$("#addtocart_"+nme+"-"+id).hide();}else{$("#addtocart_"+nme+"-"+id).show();}});}
function changeAllTeamNames(teamName){$("span[id='teamName']").text(teamName);}
function hideBody(nme){$("#"+nme).hide();$("#loading").show();$("#"+nme).empty();}
function showBody(nme){$("#"+nme).show();$("#loading").hide();$("select[id^='ticketCategory_']").change(function(){var mID;var nme;str=this.id;mID=str.slice((str.indexOf("-")+1),str.length);nme=str.slice((str.indexOf("_")+1),str.indexOf("-"));updateItemCost(mID,$(this).val(),nme);});$("input[id^='qty_']").keydown(function(event){if(event.keyCode==46||event.keyCode==8){}
else{if(event.keyCode<48||event.keyCode>57){if(event.keyCode<96||event.keyCode>106){event.preventDefault();}}}});$("input[id^='qty_']").keyup(function(event){var qty=$(this).val();if(isNaN(qty)){if(qty.length!=0){$(this).val(qty.slice(0,qty.length-1));}}else{var mID;var nme;var subTot=0;str=this.id;mID=str.slice((str.indexOf("-")+1),str.length);nme=str.slice((str.indexOf("_")+1),str.indexOf("-"));if(nme=="pack"){subTot=$("#"+mID+"_h"+$("#selRating_"+mID+"").val()+""+$("#selOccupancy_"+mID+"").val()).val();}
else{subTot=$("#indvCost_"+nme+"-"+mID).val();}
subTot=(subTot.toString()).replace(",","");subTot=Number(subTot)*qty;subTot=subTot.toFixed(2);$("#cost_"+nme+"-"+mID).html("USD "+addCommas(subTot));}});}
function tallyUpPack(mID,typ){var qty=0;if($("#qty_pack-"+mID+""+typ+"").val()!=""){qty=parseInt($("#qty_pack-"+mID+""+typ+"").val());}
subTot=$("#"+mID+""+typ+"_h"+$("#selRating_"+mID+""+typ+"").val()+""+$("#selOccupancy_"+mID+""+typ+"").val()).val();subTot=(subTot.toString()).replace(",","");subTot=Number(subTot)*qty;subTot=subTot.toFixed(2);$("#cost_pack-"+mID+typ+"").html("USD "+addCommas(subTot));}
function addPackToCart(id,typ){var qty=$("#qty_pack-"+id+typ+"").val();var chkr=true;if(qty!=0){if($("#selOccupancy_"+id+""+typ).val()=="d"){if((qty/2)!=(parseInt(qty/2))){chkr=false;}}
if(chkr){var cost=$("#"+id+""+typ+"_h"+$("#selRating_"+id+""+typ+"").val()+""+$("#selOccupancy_"+id+""+typ+"").val()).val();var costid=$("#"+id+""+typ+"_h"+$("#selRating_"+id+""+typ+"").val()+""+$("#selOccupancy_"+id+""+typ+"").val()).attr("name");var catid=0;var nme="pack";cartItems++;var cartStr=id+"-"+qty+"-"+cost+"-"+catid+"-"+nme+"-"+costid+"-"+cartItems;var cartList=($.cookie('ord')==null)?cartStr:$.cookie('ord')+","+cartStr;$.cookie('ord',cartList,{expires:7,path:'/'});$("#list_"+nme+"-"+id+""+typ).fadeOut(500,function(){$("#listHide_"+nme+"-"+id+""+typ).fadeIn(500,function(){setTimeout("showItem('"+id+""+typ+"','"+nme+"');",2000);$("#bundlelist").append(buildCartItem(id,qty,cost,catid,nme));tallyCartTotal();});});}else{alert("You can only enter multiples of 2 (even numbers) for double occupancy.");}}}
function addActToCart(id,typ){var qty=$("#qty_act-"+typ+id+"").val();var chkr=true;if(qty!=0){var cost=$("#indvCost_act-"+typ+id+"").val();var costid=id;var catid=0;var nme="act";cartItems++;var cartStr=id+"-"+qty+"-"+cost+"-"+catid+"-"+nme+"-"+costid+"-"+cartItems;var cartList=($.cookie('ord')==null)?cartStr:$.cookie('ord')+","+cartStr;$.cookie('ord',cartList,{expires:7,path:'/'});$("#list_"+nme+"-"+typ+id).fadeOut(500,function(){$("#listHide_"+nme+"-"+typ+id).fadeIn(500,function(){setTimeout("showItem('"+typ+id+"','"+nme+"');",2000);$("#bundlelist").append(buildCartItem(id,qty,cost,catid,nme));tallyCartTotal();});});}}
function triggerSelect(nme,id){$("#"+nme+" option[value='"+id+"']").attr('selected','selected').trigger('change');}
function initHandlers(){$("select[id^='ticketCategory_match-z'] option:selected").removeAttr('selected');$("select[id^='ticketCategory_match-z'] option:eq(0)").attr("selected","selected");$("input[id^='qty_match-z']").val("1");$("select[id^='select_']").change(function(){var selectedTeam;var elem=this.id;teamID=$(this).val();elem=elem.slice(elem.indexOf("_")+1,elem.length);var selectedTeam=$("#select_"+elem+" option:selected").text();if(teamID!=0){hideBody("body_"+elem);$("#body_"+elem).load("../inc/ajax."+elem+".php",{id:$(this).val()},function(){changeAllTeamNames(selectedTeam);showBody("body_"+elem);});}});$('#datepicker_from1').datepicker({numberOfMonths:1,minDate:new Date(2010,5,11),maxDate:new Date(2010,6,11),dateFormat:'yy-mm-dd',altField:'#altDateFrom',altFormat:'DD, d MM'});$('#datepicker_to1').datepicker({numberOfMonths:1,minDate:new Date(2010,5,11),maxDate:new Date(2010,6,11),defaultDate:new Date(2010,6,11),dateFormat:'yy-mm-dd',altField:'#altDateTo',altFormat:'DD, d MM'});$("a[id^='picker_']").click(function(){var elem=this.id;var todate="";var fromdate="";elem=elem.slice(elem.indexOf("_")+1,elem.length);todate=$('#datepicker_to1').val();fromdate=$('#datepicker_from1').val();hideBody("body_"+elem);$("#date_results_heading").show();$("#date_results_heading").html("<br>"+jsPackTicketsResults+": "+$('#altDateFrom').val()+" - "+$('#altDateTo').val());$("#body_"+elem).load("../inc/ajax."+elem+".php",{todate:todate,fromdate:fromdate},function(){showBody("body_"+elem);});});}
function tstOptionsTog(){if($('#tstOptions').is(':visible')){$("#tstOptions").hide();}else{$("#tstOptions").show();}}
function showAllMatches(){if($('#teamMatches,#teamMatchesCity').is(':visible')){$("#teamMatches,#teamMatchesCity").hide();$("#allMatchesHidden").show();$("#btnAllMatches").html("<br><br>Team matches");}else{$("#teamMatches,#teamMatchesCity").show();$("#allMatchesHidden").hide();$("#btnAllMatches").html("Show all matches");}}
$().ready(function(){initCart();initHandlers();});
