	/* Populate Giving Opportunities */ 
	function renderGivingOpportunities(xml){
		var oddEven = "odd";
	
    	$(xml).find('opportunity').each(function(){
    		
	    	var id = $(this).attr('ID');
	        var name = $(this).attr('Name');
	        var description = $(this).attr('Description');
	        var partnerName = $(this).attr('PartnerName');
	        var amount1 = $(this).attr('Amount1');
	        var amount2 = $(this).attr('Amount2');
	        var amount3 = $(this).attr('Amount3');
	        var amount4 = $(this).attr('Amount4');
	        var amount5 = $(this).attr('Amount5');
	        var slots = $(this).attr('Capacity');
	        var estimated = $(this).attr('Estimated');
	        
	        
	        var amount = "";
	        if (amount1 != '')
	        	amount = '$' + amount1;
	        else
	        	amount = "Any Amount"
	        if (amount2 != '')
	        	amount = '$' + amount1 + " - $" + amount2;
	        if (amount3 != '')
	        	amount = '$' + amount1 + " - $" + amount3;
	        if (amount4 != '')
	        	amount = '$' + amount1 + " - $" + amount4;
	        if (amount5 != '')
	        	amount = '$' + amount1 + " - $" + amount5;
	        
      		var oppRow = $('<tr class="standard ' + oddEven + '" id="opp' + id + '"></tr>');
      		var oppDetailRow = $('<tr class="detailRow expand-child" id="oppDetail' + id + '" style="display: none"></tr>');
			
		
			
			$('<td nowrap></td>')
				.html(name)
				.appendTo(oppRow);
			
			$('<td nowrap></td>')
				.html(partnerName)
				.appendTo(oppRow);
			
			$('<td nowrap></td>')
				.html(amount)
				.appendTo(oppRow);
				
			$('<td colspan="5" style="text-align:center;"></td>')
				.html('<img src="images/spinning_big.gif" width="32" height="32" />')
				.appendTo(oppDetailRow);
				
			oppRow.click(function(){
				if (activeRow != ""){
					$("#oppDetail" + activeRow).hide();
					$("#opp" + activeRow).removeClass("selectedRow");
				}
				$(this).addClass("selectedRow");
      			$('#oppDetail' + id).show();
      			
      			
      			$.get("includes/details_giving.php",{oid:id},function(temp){
					$('#oppDetail' + id).html(temp);
				
					$('#details' + id).html(description);
				
					if (slots == '' || slots > 0) {
						var amountList = $('#amountList' + id);
						
						if (estimated != "1"){
						
							if (amount2 == ''){
								$('<li></li>')
									.html('<b>$</b><input class="amountInput" type="text" id="amount' + id + '" value="' + amount1 + '" />') 
									.appendTo(amountList);
								
								$('#amount' + id).constrainInput({allowedCharsRegex: "\\d+"});
							
							} else {
								$('<li></li>')
									.html('<input type="radio" id="amount1' + id + '" name="amount' + id + '" value="' + amount1 + '" checked /> $' + amount1) 
									.appendTo(amountList);
								$('<li></li>')
									.html('<input type="radio" id="amount2' + id + '" name="amount' + id + '" value="' + amount2 + '" /> $' + amount2) 
									.appendTo(amountList);
								if (amount3 != '')
									$('<li></li>')
										.html('<input type="radio" id="amount3' + id + '" name="amount' + id + '" value="' + amount3 + '" /> $' + amount3) 
										.appendTo(amountList);
								if (amount4 != '')
									$('<li></li>')
										.html('<input type="radio" id="amount4' + id + '" name="amount' + id + '" value="' + amount4 + '" /> $' + amount4) 
										.appendTo(amountList);
								if (amount5 != '')
									$('<li></li>')
										.html('<input type="radio" id="amount5' + id + '" name="amount' + id + '" value="' + amount5 + '" /> $' + amount5) 
										.appendTo(amountList);
								$('<li></li>')
									.html('<input type="radio" id="amount6' + id + '" name="amount' + id + '" value="0" /> <b>$</b><input class="amountInput" type="text" id="amountOther' + id + '" />') 
									.appendTo(amountList);
								
								$('#amountOther' + id).click(function(){
								
									$('#amount6' + id).attr("checked", "checked");
								
								});
							
								$('#amountOther' + id).constrainInput({allowedCharsRegex: "\\d+"});
							
							}
						}
						$('#add' + id).click(function(){
							var amt = '0';
							if (estimated != '1'){
								if (amount2 == '') {
									amt = $('#amount' + id).val();
								}else{
									amt = $('input[name="amount' + id + '"]:checked').val();
									if (amt == '0')
										amt = $('#amountOther' + id).val();
								}
							}
							if ((amt != '' && amt != '0') || estimated == '1'){
							
								$.get("addToCart.php",
									{sid:sessionID,oid:id,quantity:1, amount:amt},
									function(){
										$.get("getCart.php",function(xml){renderCart(xml)}); 
									});
							
								$('#oppDetail' + id)
									.find('.options')
									.effect("transfer", {to: "#cartbox"},800);
								$('#oppDetail' + id)
									.find('.options')
									.html('This opportunity has been<br>added to your basket.');
							}
						});
					} else {
					
						$('#oppDetail' + id)
							.find('.options')
							.html('There are no more slots available.');
						
					}
      			});
      			
      			activeRow = id;
      		});
      		

				
			
		
			
        	oppRow
            	.appendTo('#opps');
        	oppDetailRow
            	.appendTo('#opps');
           	
           	if (oddEven == "odd")
           		oddEven = "even";
           	else
           		oddEven = "odd";
   		});
   		
   		$("#opportunities").tablesorter(
   			{widgets: ['zebra']}
   		); 
   			
   		$("#opportunities tr.standard").hover(
   			function(){
			    $(this).addClass("highlight");
   			},
   			function(){
			    $(this).removeClass("highlight");
   			});


		$("#loading").hide();
		$("#opportunities").show();
    }





/* Populate Service Opportunities */ 
	function renderServiceOpportunities(xml){
	
		
		var flag = true;
		var oddEven = "odd";
	
    	$(xml).find('opportunity').each(function(){
    		flag = false;
    		
	    	var id = $(this).attr('ID');
        var campus = $(this).attr('Campus');
        var name = $(this).attr('Name');
        var espanol = $(this).attr('Espanol');
        var family = $(this).attr('FamilyFriendly');
        var money = $(this).attr('RequiresMoney');
        var description = $(this).attr('Description');
        var groupName = $(this).attr('GroupName');
        var partnerName = $(this).attr('PartnerName');
        var startDate = $(this).attr('StartDate');
        var endDate = $(this).attr('EndDate');
        var startTime = $(this).attr('StartTime');
        var endTime = $(this).attr('EndTime');
        var slots = $(this).attr('Capacity');
        var closed = $(this).attr('Closed');
        
        var opts = false;
	        
	      if (closed == 0) {
        if (espanol == "1" || family == "1" || money == "1" || (groupName != "" && groupName != "Any Groups")) {
        	description += "<div class='variables'>";
        	if (espanol == "1") {
        		description += "Spanish Speaking a Plus"; 
        		opts = true;
        	}
        	if (family == "1") {
        		if (opts)
        			description += ", Family Friendly";
        		else
        			description += "Family Friendly";
        		opts = true;
        	}
        	if (money == "1") {
        		if (opts)
        			description += ", Requires Money";
        		else
        			description += "Requires Money";
        		opts = true;
        	}
        	if (groupName != "" && groupName != "Any Groups"){
        		if (opts)
        			description += ", " + groupName + " Only";
        		else
        			description += groupName + " Only";
        		opts = true;
        	} 
        		
        	description += "</div>";
       	}
	        
        //if (espanol == '1')
        	//name = name + ' <img src="images/esp.gif" width="20" height="11" align="top" />';
        
    		var oppRow = $('<tr class="standard ' + oddEven + '" id="opp' + id + '"></tr>');
    		var oppDetailRow = $('<tr class="detailRow expand-child" id="oppDetail' + id + '" style="display: none"></tr>');
			
		
				$('<td nowrap></td>')
					.html(startDate)
					.appendTo(oppRow);
				
				$('<td nowrap></td>')
					.html(startTime + " to " + endTime)
					.appendTo(oppRow);
		
				
				$('<td></td>')
					.html(name)
					.appendTo(oppRow);
					
				$('<td nowrap></td>')
					.html(partnerName)
					.appendTo(oppRow);
				
				$('<td nowrap></td>')
					.html(campus)
					.appendTo(oppRow);
				
				
				if (slots > 0 && closed == 0){
					$('<td></td>')
						.html(slots)
						.appendTo(oppRow);
				} else {
					$('<td></td>')
						.html('Closed')
						.appendTo(oppRow);
				}
				
				$('<td colspan="6" style="text-align:center;"></td>')
					.html('<img src="images/spinning_big.gif" width="32" height="32" />')
					.appendTo(oppDetailRow);
					
				oppRow.click(function(){
					if (activeRow != ""){
						$("#oppDetail" + activeRow).hide();
						$("#opp" + activeRow).removeClass("selectedRow");
					}
					$(this).addClass("selectedRow");
	      		$('#oppDetail' + id).show();
					
					
					$.get("includes/details.php",{oid:id},function(temp){
						$('#oppDetail' + id).html(temp);
					
						$('#details' + id).html(description);
					
						if (slots > 0 && closed == 0) {
							var quantitySelect = $('#form' + id + ' > .quantity');
					
							for (i=1;i<=slots;i++) {
								$('<option></option>').html(i).val(i)
									.appendTo(quantitySelect);
								if (id == "294")
									break;
							}
					
							$('#add' + id).click(function(){
								$.get("addToCart.php",
									{sid:sessionID,oid:id,quantity: quantitySelect.val(), amount:1},
									function(){
										$.get("getCart.php",function(xml){renderCart(xml)}); 
									});
								
								$('#oppDetail' + id)
									.find('.options')
									.effect("transfer", {to: "#cartbox"},800);
								$('#oppDetail' + id)
									.find('.options')
									.html('This opportunity has been<br>added to your basket.');
							
							});
						} else {
							if (closed == 0)
								$('#oppDetail' + id)
									.find('.options')
									.html('There are no more slots available.');
							else
								$('#oppDetail' + id)
									.find('.options')
									.html('Registration has closed for this opportunity.');
								
						}
					});
					
					
	      			activeRow = id;
	      		});
					
					 
				
	        	oppRow
	            	.appendTo('#opportunities');
	        	oppDetailRow
	            	.appendTo('#opportunities');
	           	
	           	if (oddEven == "odd")
	           		oddEven = "even";
	           	else
	           		oddEven = "odd";
	           		}
	   		});
   		
   		if (flag) {
   			var oppRow = $('<tr></tr>');
      					
		
				$('<td colspan="6" style="text-align: center; font-size: 14px; padding: 10px;" nowrap></td>')
					.html("There are currently no opportunities. Try refining your search.")
					.appendTo(oppRow);
				
				oppRow
            	.appendTo('#opportunities');
   		}else{
	   		$("#opportunities tr.standard").hover(
	   			function(){
				    $(this).addClass("highlight");
	   			},
	   			function(){
				    $(this).removeClass("highlight");
	   			});
	   			
   		}
   		

   			
   		

		$("#loading").hide();
		$("#opportunities").show();
    }
    
    
    
	
    
    
    
    
    
 (function($){
 $.fn.constrainInput = function(config){
    var settings = $.extend({
       allowedCharsRegex: ".*"
    }, config);
       var re = new RegExp(settings.allowedCharsRegex);
    $.each(this, function(){
      var input = $(this);
      
      var keypressEvent = function(e){
        e= e || window.event;
        var k = e.charCode || e.keyCode || e.which;
        if(e.ctrlKey || e.altKey || k == 8){//Ignore
          return true;
        } else if ((k >= 41 && k <= 122) ||k == 32 || k > 186){//typeable characters
          return (re.test(String.fromCharCode(k)));
        }
        return false;
      }
      input.bind("keypress",keypressEvent);
    });
    return this;
  };
})(jQuery);