$(document).ready(function(){
	
	$("#usebilling").click(function(){
		SwapBilling();
	});
	
	function SwapBilling() {
		if($("#usebilling:checked").is(':checked')){
			for(i=1; i<13; i++){
				$("#s_"+i).val($("#b_"+i).val());
			}		
		}else{
			for(i=1; i<13; i++){
				$("#s_"+i).val('');
			}
		}
	}
	
	$('.helpIcon').tipTip({ maxWidth: 'auto', defaultPosition: 'top' });
	
	if($("#school-select").val()){
	$('#status').html('Loading...');
	$.ajax({  
		url: '/index.php/ajax/packages/'+$("#ses").val()+'/'+$("#school-select").val(),  
		cache: false,  
		success: function(html){    
			$('#package-result').html(html); 
			$('#status').html(''); 
		}});
	}
	
});

function opendialog()
{
	var first = $('#studentfirst').val();
	var last = $('#studentlast').val();
	var grade = $('#studentgrade').val();
	var teacher = $('#studentteacher').val();
	var school = $('#school-select option:selected').text();
	
	var fee = $(".order-bg:checked").attr('title');

	if(Number(fee) > 0){
		var extrastring = "A fee of $"+fee+" will be charged for the selected background.";
	}else{
		var extrastring = "";
	}
	
	var $dialog = $('<div></div>')
		.html('Please verify all information is correct. Incorrect information may lead to delays in delivery and additional fees.<br><br><br><b>Student Name:</b> '+first+' '+last+'<br><b>Grade:</b> '+grade+'<br><b>Teacher/Home Room:</b> '+teacher+'<br><b>School:</b>  '+school+'<br><br>'+extrastring)
		.dialog({
			autoOpen: false,
			resizable: false,
			height:300,
			modal: true,
			buttons: {
				"Confirm": function() {
					$("#studentinfo").submit();
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			},
			title: 'Is this information correct?'
		});
	$dialog.dialog('open');
}


function selectedprograms()
{
	$('#status').html('Loading...');
	$.ajax({  
	url: '/index.php/ajax/packages/'+$("#school-select").val(),  
	cache: false,  
	success: function(html){    
		$('#package-result').html(html);  
		$('#status').html('');
	}});
}

function selectedevents()
{
	$('#status').html('Loading...');
	$.ajax({  
	url: '/index.php/ajax/packages/'+$("#school-select").val()+"/"+$("#order-select").val(),  
	cache: false,  
	success: function(html){    
		$('#package-result').html(html);  
		$('#status').html('');
	}});
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
