jQuery(document).ready(function(){
	jQuery(document).on('change', '#sregion', function(e){
		var elmObj = jQuery(this);
		var regionId = jQuery(this).val();
		var route = "0";
		if(jQuery('#sroute').length){
			route = "1";
		}
		jQuery.ajax({
			type: 'POST',
			url: siteUrl+'stocks/getModelOptions.json',
			data: {reModel:'Depot', region:regionId, route:route },
			dataType: 'json',
			beforeSend: function(){
				elmObj.after('<img src="'+siteUrl+'img/loading20.gif" class="loading" />');
			},
			success: function(data){
				jQuery('.loading').remove();
				$('#sdepot').fillSelect(data.options);
				if(jQuery('#sroute').length && data.routes){
					$('#sroute').fillSelect(data.routes);
				}
			},
			statusCode: {
				404: function() {
					alert( message.noPage );
				}
			}
		});
	});
	
	
	jQuery(document).on('change', '#sdepot', function(e){
		var elmObj = jQuery(this);
		var depotId = jQuery(this).val();
		
		if(jQuery('#sroute').length){		
		
			jQuery.ajax({
				type: 'POST',
				url: siteUrl+'routes/getRoute.json',
				data: {depot:depotId},
				dataType: 'json',
				beforeSend: function(){
					elmObj.after('<img src="'+siteUrl+'img/loading20.gif" class="loading" />');
				},
				success: function(data){
					jQuery('.loading').remove();
					$('#sroute').fillSelect(data.routes);
					
				},
				statusCode: {
					404: function() {
						alert( message.noPage );
					}
				}
			});
		}
	});
	
	//State and LGA
	
	jQuery('#lg-state').change(function(){
		var elmObj = jQuery(this);
		var stateId = jQuery(this).val();
		jQuery.ajax({
			type: 'POST',
			url: siteUrl+'region/getLgaOptions.json',
			data: {reModel:'LgArea', state:stateId },
			dataType: 'json',
			beforeSend: function(){
				elmObj.after('<img src="'+siteUrl+'img/loading20.gif" class="loading" />');
			},
			success: function(data){
				jQuery('.loading').remove();
				$('#lg-area').fillSelect(data.options);
			},
			statusCode: {
				404: function() {
					alert( message.noPage );
				}
			}
		});
	});
	
	jQuery(document).on("click", '.verify-it',  function(){
		
		var elmObj = jQuery(this);
		var mId = jQuery(this).attr('id');
		var mdl = jQuery(this).attr('mdl');
		if(confirm(message.confirmContinue)){
			jQuery.ajax({
				type: 'POST',
				url: siteUrl+'reports/do_verify',
				data: {mdl:mdl, mId:mId, 'unverify':0 },
				beforeSend: function(){
					elmObj.after('<img src="'+siteUrl+'img/loading20.gif" class="loading" />');
				},
				success: function(data){
					jQuery('.loading').remove();
					jQuery(elmObj).parent('div').html(data);
				},
				statusCode: {
					404: function() {
						alert( message.noPage );
					}
				}
			});
		}
	});
	
	jQuery(document).on("click", '.unverify-it', function(){		
		var elmObj = jQuery(this);
		var mId = jQuery(this).attr('id');
		var mdl = jQuery(this).attr('mdl');
		if(confirm(message.confirmContinue)){
			jQuery.ajax({
				type: 'POST',
				url: siteUrl+'reports/do_verify',
				data: {mdl:mdl, mId:mId, 'unverify':1 },
				beforeSend: function(){
					elmObj.after('<img src="'+siteUrl+'img/loading20.gif" class="loading" />');
				},
				success: function(data){
					jQuery('.loading').remove();
					jQuery(elmObj).parent('div').html(data);
				},
				statusCode: {
					404: function() {
						alert( message.noPage );
					}
				}
			});
		}
	});
});