	$(document).ready(function() {
		
	
		$('#dob').datepicker({
			changeMonth: true,
			changeYear: true
		});
		
		$("#phonepin").hide();
		$("#replydiv").hide();
		 $('#established').hide('slow');
		 $('#Unestablished').hide('slow');
		 
		
		$("#phoneVerify").click(function() {
			
			$("#phonepin").show('slow');			
			$.ajax({
				   type: "POST",
				   url: "/user/login/phoneVerify",
				   cache:true,						   
				   success: function(msg){
				       //alert(msg);					   
		 			}
		 		});	 	 		
		});
		
		$("#replylink").click(function() {			
			$("#replydiv").show('slow');			
		});
		
		$("#blockuser").click(function() {		
					
			var check_count = $("#usersTable :input:checkbox:checked").size();
			if(check_count > 0){
				var ids   = new Array()
				$("#usersTable :input:checkbox:checked").each(function(){
					 ids.push(this.value);			                
				});
				
				$.ajax({
					   type: "POST",
					   url: "/admin/blockUsers",
					   cache:true,
					   data: "user_id="+ids,
					   success: function(msg){
							if(msg==""){
							   $("#usersList").html("<div style='margin:50px;color:red;'>No Record Found</div>");
							}else{
							   $("#usersList").html(msg);
							}
							$("table").dataTable();
					   }
					});	 
			} else {
				alert("No users selected");
			}
					
		});
		
		$("#delete_comment").click(function() {		
			
			var check_count = $("#commentsListing :input:checkbox:checked").size();
			if(check_count > 0){
				var ids   = new Array();
				$("#commentsListing :input:checkbox:checked").each(function(){
					 ids.push(this.value);			                
				});
				
				$.ajax({
					   type: "POST",
					   url: "/admin/deleteComments",
					   cache:true,
					   data: "comment_id="+ids,
					   success: function(msg){
							if(msg==""){
							   $("#listCategoryTable02").html("<div style='margin:50px;color:red;'>No Records Found</div>");
							}else{
							   $("#listCategoryTable02").html(msg);
							}
							$("table").dataTable();
					   }
					});	 
			} else {
				alert("You have not selected any comment from the list.");
			}
			
		});		
		
		
		$("#delete_watch").click(function() {		
			
			var check_count = $("#example :input:checkbox:checked").size();
			if(check_count > 0){
				var ids   = new Array()
			    $("#example :input:checkbox:checked").each(function(){
			         ids.push(this.value);			                
			    });
				
				$.ajax({
					   type: "POST",
					   url: "/user/login/deleteWatchlist",
					   cache:true,
					   data: "auction_id="+ids,
					   success: function(msg){
				        	if(msg==""){
						       $("#listCategoryTable02").html("<div style='margin:50px;color:red;'>No Record Found</div>");
						    }else{
							   $("#listCategoryTable02").html(msg);
						    }
							$("table").dataTable();
				       }
			 		});	 
			} else {
				alert("No auction selected");
			}
			
		});
	
		$("#watchList").click(function() {
			$.ajax({
				   type: "POST",
				   url: "/buyer/addToWatchList",
				   cache:true,						   
				   success: function(msg){
				    $("#listingAppImage").html(msg);
			}
		 		});	 
		});
				$('#example1').dataTable( {
					bPaginate: false,
					bSort: true
					} );
				
				$('#example').dataTable({ bPaginate: true,
            bSort: true,
            iDisplayLength: 20,
            aoColumns: [ { sType: 'numeric' },
						 { sType: 'string' },
						 { sType: ['numeric' ]},
                         { bSortable: true },
                         { bSortable: true },
                         { sType: 'numeric' },
                         { bSortable: 'date' },
                         { bSortable: 'date' }]
          });
		  
		  $('#exampleImg').dataTable({ bPaginate: true,
            bSort: true,
            iDisplayLength: 10,
            aoColumns: [ { bSortable: true },
                         { sType: ['numeric']},
						 { sType: ['numeric']},
                         { sType: 'numeric' },
                         { sType: 'numeric' },
                         { bSortable: 'date' },
                         { bSortable: 'date' }]
          });
				 //$("table").dataTable();
				
				 $('#mybidtable').dataTable( {
						
						"aoColumns": [
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [  ] },
							{ "asSorting": [ "desc", "asc", "asc" ] },	
							{ "asSorting": [ "desc", "asc", "asc" ] },	
							{ "asSorting": [ "desc", "asc", "asc" ] }
						]
					} );
				 
				 $('#mywatchtable').dataTable( {
						
						"aoColumns": [
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [ "desc", "asc", "asc" ] }
						]
					} );
					
				$('#mylistingtable').dataTable( {
						
						"aoColumns": [
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [ "desc", "asc", "asc" ] }
						]
					} );
					
				$('#mywatchtable12').dataTable( {
						
						"aoColumns": [
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [ "desc", "asc", "asc" ] }
						]
					} );
					
				 $('#usersTable').dataTable( {
						"aaSorting": [[4,'desc'], [0,'asc']]
					} );
				
				 $('#commentsListing').dataTable( {
						
						"aoColumns": [
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [ "desc", "asc", "asc" ] },								
							{ "asSorting": [ "desc", "asc", "asc" ] }
						]
					} );
				 
				 $('#newListing').dataTable( {
						
						"aoColumns": [
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [ "desc", "asc", "asc" ] },	
							{ "asSorting": [ "desc", "asc", "asc" ] },	
							{ "asSorting": [ "desc", "asc", "asc" ] },	
							{ "asSorting": [ "desc", "asc", "asc" ] },	
							{ "asSorting": [ "desc", "asc", "asc" ] }
						]
					} );
					
				 $('#closedListing').dataTable( {
						
						"aoColumns": [
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [ "desc", "asc", "asc" ] },
							{ "asSorting": [ "desc", "asc", "asc" ] },	
							{ "asSorting": [ "desc", "asc", "asc" ] },	
							{ "asSorting": [ "desc", "asc", "asc" ] },	
							{ "asSorting": [ "desc", "asc", "asc" ] },	
							{ "asSorting": [ "desc", "asc", "asc" ] }
						]
					} );
				 
			/*	$("#listTabs").find("a").click(function(event) {
			
				   var current_id = $(this).attr("id");
				 		$.ajax({
						   type: "POST",
						   url: "/buyer/searchByFilter",
						   cache:true,
						   data: "id_search="+current_id,
						   success: function(msg){
					       if(msg==""){
					    	   $("#listCategoryTable").html("<div style='margin:50px;color:red;'>No Matched Record Found</div>");
					       }else{
						   $("#listCategoryTable").html(msg);
					       }
						   $("table").dataTable();
					}
				});	    
				 event.preventDefault();
			 });*/
				
				
				$("#selectList").change(onSelectChange);
				function onSelectChange(){
					    var selected = $("#selectList option:selected");    
						 
						    if(selected.val() != 0){
						    				    	
						    	 var current_id = selected.val()
						    	
						    	
							 		$.ajax({
									   type: "POST",
									   url: "/buyer/searchByFilter",
									   cache:true,
									   data: "id_search="+current_id,
									   success: function(msg1){
								       if(msg1==""){
								    	   $("#listCategoryTable").html("<div style='margin:50px;color:red;'>No Matched Record Found</div>");
								       }else{
									   $("#listCategoryTable").html(msg1);
									   alert(msg1);
								       }
									   $("table").dataTable();
								}
							});	   				            
						    }		  
					}
			} );
	
	function paginate(page, type){
		
		if(type == 'sent')  {
			var controller = 'sent_items';
			var showdiv = 'sentItemsList';
		} else if(type == 'inbox'){ 
			var controller = 'inbox';
			var showdiv = 'inboxList';
		}
		$.ajax({
			   type: "POST",
			   url: "/user/login/"+controller,
			   cache:true,	
			   data: "page="+page,
			   success: function(msg){
					if(msg==""){
			    	   $("#"+showdiv).html("<div style='margin:50px;color:red;'>No Matched Record Found</div>");
			        } else {
			    	   $("#"+showdiv).html(msg);
			        }					   
	 			}
	 		});	 
	 			
	}
	
	
	function getMainCategory(id){
		select(id);
		
		$.ajax({
			   type: "POST",
			   url: "/buyer/getMainCategory",
			   cache:true,
			   data: "id_search="+id,
			   success: function(msg){
		       if(msg==""){
		    	   $("#listCategoryTable").html("<div style='margin:50px;color:red;'>No Matched Record Found</div>");
		       }else{
			   $("#listCategoryTable").html(msg);
		       }
			   $("table").dataTable();
		}
	});	    
	}	
	
	function getcategory(id){
		select(id);
		
		$.ajax({
			   type: "POST",
			   url: "/buyer/getcategory",
			   cache:true,
			   data: "id_search="+id,
			   success: function(msg){
		       if(msg==""){
		    	   $("#listCategoryTable").html("<div style='margin:50px;color:red;'>No Matched Record Found</div>");
		       }else{
			   $("#listCategoryTable").html(msg);
		       }
			   $("table").dataTable();
		}
	});	    
	
	}
	
	function getAppCategory(id){
		select(id);
		$.ajax({
			   type: "POST",
			   url: "/buyer/getAppCategory",
			   cache:true,
			   data: "id_search="+id,
			   success: function(msg){
		       if(msg==""){
		    	   $("#listCategoryTable").html("<div style='margin:50px;color:red;'>No Matched Record Found</div>");
		       }else{
			   $("#listCategoryTable").html(msg);
		       }
			   $("table").dataTable();
		}
	});	    
	
	}
		
	function AllTypes(id){
	
	
		select(id);
			
		$.ajax({
			   type: "POST",
			   url: "/buyer/AllTypes",
			   cache:true,
			   data: "id_search="+id,
			   success: function(msg){
			   document.getElementById("aloader").style.display = 'block';
		       if(msg==""){
		    	   $("#listCategoryTable").html("<div style='margin:50px;color:red;'>No Matched Record Found</div>");
		       }else{
			    document.getElementById("aloader").style.display = 'none';
			   $("#listCategoryTable").html(msg);
		       }
			   $("table").dataTable();
		}
	});	    
	
	}
	
	function select(id){
	   if(id =='1'){
			$('#one').addClass('newClass')
			$('#two').removeClass('newClass')
			$('#three').removeClass('newClass')
		
		}	
		
		if(id =='2'){
			$('#two').addClass('newClass')
			$('#one').removeClass('newClass')
			$('#three').removeClass('newClass')
		
		}
		
		if(id =='0'){
			$('#three').addClass('newClass')
			$('#two').removeClass('newClass')
			$('#one').removeClass('newClass')
		
		}
	
	}
	
	 function approvedStatus(id){
		 $.ajax({
		    type: "POST",
		    url: "http://buysellapp.com/admin/approvedStatus",
		    cache:true,
		    data: "id="+id,
		    success: function(msg){
		   if(msg==""){
		        $("#listCategoryTable").html("<div style='margin:50px;color:red;'>No Matched Record Found</div>");
		        }else{
		    $("#listCategoryTable").html(msg);
		        }
		    $("table").dataTable();
		 }
		 });     
	 }

		 function rejectedStatus(id){
			 $.ajax({
			    type: "POST",
			    url: "http://buysellapp.com/admin/rejectedStatus",
			    cache:true,
			    data: "id="+id,
			    success: function(msg){
			   if(msg==""){
			        $("#listCategoryTable").html("<div style='margin:50px;color:red;'>No Matched Record Found</div>");
			        }else{
			        	$("#listCategoryTable").html(msg);
			        }
			    $("table").dataTable();
			 }
			 }); 
		 }	
		 
		 function listUsers(type){			
			 
			 if(type == 'all'){
				$('#one').addClass('left last onselect');
				$('#two').removeClass('onselect');
				$('#three').removeClass('onselect');
				$('#four').removeClass('onselect');
				$('#five').removeClass('onselect');	
			} else if(type == 'verified'){
				$('#one').removeClass('onselect');
				$('#two').addClass('left last onselect');
				$('#three').removeClass('onselect');
				$('#four').removeClass('onselect');	
				$('#five').removeClass('onselect');	
			} else if(type == 'blocked'){
				$('#one').removeClass('onselect');
				$('#two').removeClass('onselect');	
				$('#three').addClass('left last onselect');
				$('#four').removeClass('onselect');
				$('#five').removeClass('onselect');	
			} else if(type == 'notverified'){
				$('#one').removeClass('onselect');
				$('#two').removeClass('onselect');	
				$('#three').removeClass('onselect');	
				$('#four').addClass('left last onselect');	
				$('#five').removeClass('onselect');	
			} else if(type == 'bidusers'){
				$('#one').removeClass('onselect');
				$('#two').removeClass('onselect');	
				$('#three').removeClass('onselect');	
				$('#four').removeClass('onselect');
				$('#five').addClass('left last onselect');
			}					
			 
			$.ajax({
				   type: "POST",
				   url: "/admin/usersListUponType",
				   cache:true,
				   data: "type="+type,
				   success: function(msg){
			        	if(msg==""){
					       $("#usersList").html("<div style='margin:50px;color:red;'>No Users</div>");
					    }else{
						   $("#usersList").html(msg);
					    }
			        	$("table").dataTable();
			       }
		 		});	 							 
		 }

		function setBidderStatus(userId, status, type){
			var type = type;
			
			$.ajax({
				   type: "POST",
				   url: "/admin/userBidderStatus",
				   cache:true,
				   data: "type="+type+"&user_id="+userId+"&status="+status,
				   success: function(msg){
			        	if(msg==""){
					       $("#usersList").html("<div style='margin:50px;color:red;'>No Users</div>");
					    }else{
						   $("#usersList").html(msg);
					    }
			        	$("table").dataTable();
			       }
		 		});	 			
		}
		
		function limitText(limitField, limitCount, limitNum) {
			
			if (limitField.value.length > limitNum) {
				limitField.value = limitField.value.substring(0, limitNum);
				alert("Maximum character length reached.");
			} else {
				$("#"+limitCount).html(limitNum - limitField.value.length);
			}
		}


			function chkMsg(){
			 
			 var message = $('#body').val();
			 if(message == ''){
				 var confrm =  confirm('Do you want to send an empty message?');
				 if(confrm){
					 return true;
				 } else {
					 return false;
				 }
			 } else {
				 return true;
			 }
		 }
		 
		 		 function reopen(id,file){
			 			 
			 window.open('http://buysellapp.com/admin/reopen_auction/'+id+'/'+file, "myWindow", 
					 "status = 1, height = 360, width = 400, resizable = 0");
		 }
		 
		 function blockAuction(aucid){
			 
			 var confrm = confirm('Do you really want to BLOCK this Auction?');
			 if(confrm){
				 $.ajax({
					   type: "POST",
					   url: "/admin/block_auction",
					   cache:true,
					   data: "aucid="+aucid,
					   success: function(msg){
				        	window.location.reload();
				       }
			 		});	
				 return true;
			 } else {
				 return false;
			 }			 
		 }
		 
		 function unblockAuction(aucid){
			 alert(aucid);
			 
		 }
