
jQuery(document).ready(function() {

	if ($('#ProductGridContainer').length>0){
		loadLineItems();
		bindButtons();
	}
	
	$('#ProductGridContainer').show();

});

function loadLineItems(){
	$.get('/dealreg_ajax.asp',{Mode:'listLineItems',DealID:DealID,nt: (new Date().getTime())},function(cartHTML){
		$('#ProductGrid').html(cartHTML);
		bindButtons();
	});
}

function bindButtons(){

	$('#AddLineItem').click(function(){
		var newPartID = $('#newPartID').val();
		var newPartQTY = $('#newQty').val();
		//alert('here');
		$.get('/dealreg_ajax.asp',{Mode:'addLineItem',DealID:DealID,PartID:newPartID,QTY:newPartQTY,nt: (new Date().getTime())},function(){
			loadLineItems();
			
		});
	});
	
	$('.Delete').click(function(){
		var deleteLineItemID = $(this).attr('rel');
		//alert(deleteLineItemID);
		$.get('/dealreg_ajax.asp',{Mode:'delLineItem',DealID:DealID,LineItemID:deleteLineItemID,nt: (new Date().getTime())},function(){
			loadLineItems();
			
		});
		
	});

}

function loadCountryApprover(ctry){
	$.get('/dealreg_ajaxCountry.asp',{Mode:'Approver',Country:ctry},function(country){
		$('#CountryApprover').html(country);
		$('#txtCountryApprover').val(country);
	});
}

function loadCountryApproverID(ctry){
	$.get('/dealreg_ajaxCountry.asp',{Mode:'ApproverID',Country:ctry},function(country){
		$('#intCountryApprover').val(country);
	});
}

function loadCountryRegion(ctry){
	$.get('/dealreg_ajaxCountry.asp',{Mode:'Region',Country:ctry},function(country){
		$('#Region').html(country);
		$('#txtRegion').val(country);
	});
}

$(function() {
	$('#Select1').change(function(){
		var x = $(this).val();

		if ($('#Select1').selectedIndex == 1){
			$('#country-other').show();}
		else {
			$('#country-other').hide();
		};

		loadCountryApprover(x);
		loadCountryApproverID(x);
		loadCountryRegion(x);
		
		});

	});



