/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 $(document).ready(function()
	{
	$("[name=orderid-selectall]").click(function(){
		if(this.checked)
			$(".listLocCheck").prop('checked',true);
		else
			$(".listLocCheck").prop('checked',false);
	});
	$(".listLocCheck").click(function(){
	if($(".listLocCheck:checked").size()==$(".listLocCheck").size())
		{
			$("[name=orderid-selectall]").prop('checked',true);
		}
	else
		{
			$("[name=orderid-selectall]").prop('checked',false);
		}
	
	});
	$("[task=delete]").click(function(){
		var ID=$(this).attr('locid');
		jConfirm(confirmation,'Alert', function(r) {
	   		if(r==true)
				{
				window.location=GLOBAL_BASE_PATH+"/location/destroy/locid/"+ID;
				}
			});
	});
	
	$("#statusUpdate").click(function(){
	   var ListAllCheckedCount = $(".listLocCheck:checked").size();
	   var status= $('#statusSelect').val();
		if($(".listLocCheck:checked").size()==0) {
				   jAlert(statusLocation);
				   return false;
		} else if(status==""){
				   jAlert(statusSelect);
				   return false; 
		}
		
		if(status=='Deleted')
		{      jConfirm(confirmation, msg, function(r) {
						if(r==true) {
								$('#locationForm').submit();
						}
				});
		} else	{
				return true;
		}
		return false;
	
	});
	$(".status-active,.status-inactive").click(function(){
		var obj=$(this);
		var data=new Object();
		data.locid=$(this).attr('locID');
		if($(this).hasClass('status-active'))
			{
			data.newClass='status-inactive icon-set';
			data.locStatus='Inactive';	
			}
		else if($(this).hasClass('status-inactive'))
			{
			data.newClass='status-active icon-set';
			data.locStatus='Active';	
			}
			$.ajax({
			   type: "POST",
			   url: GLOBAL_BASE_PATH+"/location/changestatus/",
			   data:data,
			   success: function(msg){
					if(msg.trim()=="")
						{
						jNotifyShow(statusChange, "common_message","message_success");
						obj.attr('class',data.newClass+' hide-txt');
						obj.attr('title',data.locStatus);
						}
			    }
  			});	
		
	});
	
	
	$(".sort").click(function(){
		$(".sortdesc,.sortasc").attr('class','sort');
		$(this).attr('class','sortdesc');
		window.location=GLOBAL_BASE_PATH+"/location/field/"+$(this).attr('sort')+"/order/ds/";
	});
	$(".sortdesc").click(function(){
		$(this).attr('class','sortasc');
		window.location=GLOBAL_BASE_PATH+"/location/field/"+$(this).attr('sort')+"/order/as/";
	});
	$(".sortasc").click(function(){
		$(this).attr('class','sortdesc');
		window.location=GLOBAL_BASE_PATH+"/location/field/"+$(this).attr('sort')+"/order/ds/";
	});


});