define(['app'], function (app) {
	
    app.controller('IlearningCtrl', function ($scope,$rootScope,AppData,$location) {
    //Every module Set Same Variable//
   
    $rootScope.menucont = true;
	$rootScope.pageLoadComp = false;
    $scope.url = "../senddata/log/";
	$scope.pageurl = "../senddata/videotraining/";
	
	
	//Check Session//
	$scope.formData = {}
	$scope.formData.ismenuload = "Yes";
	if($rootScope.items == undefined || $rootScope.items == null){
		$scope.formData.ismenuload = "No";
	}

    $scope.formData.funName = "checksession";
	$scope.formData.lang = $rootScope.selLanguage;
	$scope.pageData = ilearningData[$rootScope.selLanguage];
	$scope.formData.start = 0;
    $scope.formData.limit = 2;
    $scope.viewby = '10';
    $scope.itemsPerPage = $scope.viewby;
	$scope.maxSize = 5; //Number of pager buttons to show
	$scope.currentPage = 1;
	$scope.mydatetime = new Date();
	$scope.formData.zmsecondselected =''; 
	$scope.formData.rmsecondselected ='';
	$scope.formData.amsecondselected =''; 
	$scope.formData.dealersecondselected  ='';
	$scope.formData.trainerselected ='';
	$scope.presenterselected='';
	$scope.showrmdiv='noview';
	$scope.showamdiv='noview';
	$scope.showdealerdiv='noview';
	$rootScope.sideselect = $scope.pageData.sidemenu[0];
	$scope.showparticipantzonediv='noview';
	$scope.showparticipantregiondiv='noview';
	$scope.showparticipantareadiv='noview';
	$scope.showparticipantdealerdiv='noview';
	$scope.showparticipantdscdiv='noview';
	$scope.showguestdiv='noview';
	$scope.showguestdivmodal='noview';
	$scope.zmsetting = {
		scrollableHeight: '200px',
			scrollable: true,
			enableSearch: true
		};
	
		$scope.zmsetting = {
			scrollableHeight: '200px',
			scrollable: true,
			enableSearch: true
		};
		$scope.zmsetting = {
			scrollableHeight: '200px',
			scrollable: true,
			enableSearch: true
		};


	$scope.selectedrmlist=[];
	$scope.selectedamlist=[];
	$scope.selectedzmlist=[];
	$scope.selecteddealerlist=[];
	$scope.selecteddsclist=[];

	$scope.zmlistcheckbox=[];
	$scope.rmlistcheckbox=[];
	$scope.amlistcheckbox=[];
	$scope.dealerlistcheckbox=[];
	$scope.dsclistcheckbox=[];
	
	$scope.guestzmdata=[];
	$scope.guestrmdata=[];
	$scope.guestamdata=[];

	$scope.guestzmmodel=[];
	$scope.guestrmmodel=[];
	$scope.guestammodel=[];

	$scope.example14model = [];
  $scope.setting1 = {
      scrollableHeight: '200px',
      scrollable: true,
      enableSearch: true
  };
  
  	$scope.itemlist_result=[];
  
	$scope.endtimes =[];
	$scope.starttimes = [];

	$scope.newschedule=false;
	$scope.ter='';
	$scope.role_error = '';

	$scope.valueselectedtrainer='';

	var now = new Date();
	var year = "" + now.getFullYear();
	var month = "" + (now.getMonth() + 1); if (month.length == 1) { month = "0" + month; }
	var day = "" + now.getDate(); if (day.length == 1) { day = "0" + day; }
	var hour = "" + now.getHours(); if (hour.length == 1) { hour = "0" + hour; }
	var minute = "" + now.getMinutes(); if (minute.length == 1) { minute = "0" + minute; }
	var second = "" + now.getSeconds(); if (second.length == 1) { second = "0" + second; }
	$scope.timevaluecurrent=  year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;


	
	
	
    AppData.sendData($scope.url, $scope.formData, function (res) {
			if (res.cont) {
	
				if($rootScope.items == undefined || $rootScope.items == null){
					$rootScope.items = res.item.control;
					
				}
				for(var i = 0; i < $rootScope.items.length; i++){
					if($location.path() == $rootScope.items[i].modulepath){
						$rootScope.modulename = $rootScope.items[i].modulename;
						$scope.usercontrol = String($rootScope.items[i].permission).split("|");
					}
				}



        //== Video List Display==
        $scope.videoList = function () {
         // $scope.searchvalue = ($scope.formData.mymodel != '') ? $scope.formData.mymodel : "";
          $scope.searchvalue =  "";
					var fobj = {};
					fobj.funName = "traininglist";
					fobj.lang = $rootScope.selLanguage;
					fobj.pn = $scope.currentPage;
					fobj.nr = $scope.itemsPerPage;
					fobj.key = $scope.searchvalue

					AppData.sendData($scope.pageurl, fobj, function (res) {
						$rootScope.pageLoadComp = true;
						if (res.cont) {
             // console.log("video training list --->",res)
							// $scope.tblheading = $scope.pageData.sidemenu[0].headingText;
							 $scope.itemtraininglist = res.item.training;
							 $scope.totalItems = res.item.total_records;
							// $scope.listFound = true;
							// $scope.search_box = true;
							// $scope.formData = {}
						} else {
              				console.log("Error Block --->")
							// $scope.listFound = false;
							// $scope.errorMsg = res.mess;
						}
					})
        }
        //==Call to video List Function 
        $scope.videoList();   
		
        //==For Pagination and Search Functions Below
        $scope.setPage = function (pageNo) {
					$scope.currentPage = pageNo;
				};
				$scope.pageChanged = function () {
					//console.log('Page changed to: ' + $scope.currentPage);
					$scope.videoList();
				};

				$scope.setItemsPerPage = function (num) {
					$scope.itemsPerPage = num;
					$scope.currentPage = 1; //reset to first page
					$scope.videoList();
				}
				$scope.filterData = function () {
					//console.log($scope.searchtext)
					$scope.videoList();
				}
        //===Pagination Ends Here ==
        //==Type List
        $scope.typeList = function () {
					var fobj = {};
					fobj.funName = "typelist";
					AppData.sendData($scope.pageurl, fobj, function (res) {
						if (res.cont) {
							$scope.typelists = res.item;
							//console.log("$scope.typelists---->",$scope.typelists)
						} else {
              				console.log("Error typelists")
						}
					})
        }
		//==Type List===
		$scope.typeList();
	//	
        //==Role List==
        $scope.roleList = function () {
			
			var fobj = {};
			fobj.funName = "role";
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					$scope.roleuserlist=res.item;
					//console.log("roleuserlist--->",$scope.roleuserlist)
				} else {
					console.log("Error roleuserlist")
				}
			})
		}
		//==Call to Role List==
		$scope.roleList();
		//==Role User List
		//==changeRole==
		$scope.changeRole = function (){
		//	$scope.resetParticipant();
			$scope.formData.zmselected='';
			$scope.presenterselected='';
			$scope.formData.zmsecondselected='';
			$scope.formData.rmsecondselected='';
			$scope.formData.amsecondselected='';
			$scope.formData.dealersecondselected='';
			$scope.formData.trainerselected='';
			$scope.showrmdiv='noview';
			$scope.showamdiv='noview';
			$scope.showdealerdiv='noview';
			if($scope.formData.roleselected == '5'){
				$scope.gettrainerlist();
			}else{
				$scope.getuserlistzm();
			}
		}
		$scope.changezmfirst = function (){
			$scope.resetParticipant();
			$scope.selectedzmlist=[];
			var temp=$scope.formData.zmselected.split("-");
			$scope.formData.zmselectedstr=temp[0];
			$scope.presenterselected=temp[0];
			$scope.presenterselectedemail=temp[1];
			$scope.formData.zmsecondselected='';
			$scope.formData.rmsecondselected='';
			$scope.formData.amsecondselected='';
			$scope.formData.dealersecondselected='';
			$scope.formData.trainerselected='';
			$scope.showrmdiv='noview';
			$scope.showamdiv='noview';
			$scope.showdealerdiv='noview';
			$scope.showparticipantzonediv='noview';
			$scope.showparticipantregiondiv='noview';
			$scope.showparticipantareadiv='noview';
			$scope.showparticipantdealerdiv='noview';
			$scope.showparticipantdscdiv='noview';
			//$scope.getparticipantinitiallist();
		}
		$scope.changetrainerfirst = function (){
			$scope.resetParticipant();

			var tempvalue=$scope.formData.trainerselected.split("-");
			$scope.presenterselected=tempvalue[0];
			$scope.valueselectedtrainer=tempvalue[1];
		//	$scope.presenterselected=$scope.formData.trainerselected;
			
			$scope.formData.zmsecondselected='';
			$scope.formData.rmsecondselected='';
			$scope.formData.amsecondselected='';
			$scope.formData.dealersecondselected='';
			$scope.formData.zmselected='';
			$scope.showrmdiv='noview';
			$scope.showamdiv='noview';
			$scope.showdealerdiv='noview';
			if($scope.presenterselected != ''){
				//$scope.showparticipantzonediv='view';
				$scope.getparticipantinitiallist();
			}
		}
		//===
        $scope.roleUserlist = function () {
					var fobj = {};
			fobj.funName = "getroleuser";
			fobj.role = "4";
			AppData.sendData($scope.pageurl, fobj, function (res) {
				$rootScope.pageLoadComp = true;
					if (res.cont) {
						//console.log("roleUserlist--->",res)
					} else {
						console.log("Error roleUserlist --->")
					}
			})
		}
		//==
		$scope.getparticipantinitiallist = function (){
			//console.log("getparticipantinitiallist-->",$scope.formData.roleselected)
				if($scope.formData.roleselected =='5'){
					$scope.selectedzmlist.push($scope.valueselectedtrainer);
					$scope.getRMlist();
				}else{
					console.log("Error in Getting Participant List")
				}
			
		}
        //==
        $scope.getRMlist = function () {
			//==Database Call ====
			var fobj = {};
			fobj.funName = "getrmlist";
			fobj.role = "5";
			fobj.value = $scope.selectedzmlist;
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					$scope.rmlistcheckbox= res.item;
					if($scope.rmlistcheckbox.length>0){
						$scope.showparticipantregiondiv='view';
					}
				} else {
					$scope.rmlistcheckbox=[];
					console.log("Error changezmcheckbox")
				}
			})
		}  
		//==
		$scope.changeRMtoGetAM = function (){
			$scope.resetParticipant();	
			$scope.showdealerdiv='noview';
			var temp=$scope.formData.rmsecondselected.split("-");
			$scope.formData.rmsecondselectedstr=temp[0];
			$scope.presenterselectedemail=temp[1];
			if($scope.formData.roleselected == '6'){
				
				$scope.presenterselected=$scope.formData.rmsecondselectedstr;
				$scope.getparticipantinitiallist();
			}else{
				$scope.showamdiv='view';
				$scope.getAMlistParticipator();
			}
			
		}
		//==
		$scope.getRMlistParticipator = function () {
			//alert("$scope.formData.zmsecondselected-->"+$scope.formData.zmsecondselected)
			var fobj = {};
			fobj.funName = "getrmuser";
			fobj.pid=$scope.formData.zmsecondselected;
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					$scope.rmseconduserlist=res.item;
				} else {
					console.log("Error rmseconduserlist")
				}
			})
			}
			//==
			$scope.getAMlistParticipator = function () {
				var fobj = {};
				fobj.funName = "getamuser";
				fobj.pid=$scope.formData.rmsecondselectedstr;
				AppData.sendData($scope.pageurl, fobj, function (res) {
					if (res.cont) {
						$scope.amseconduserlist=res.item;
					} else {
						console.log("Error amseconduserlist")
					}
				})
				}        	
		//==
		$scope.changeZmtogetRM = function (){
			$scope.showrmdiv="view";
			$scope.showamdiv='noview';
			$scope.showdealerdiv='noview';
			$scope.getRMlistParticipator();
		}
		//===
		$scope.changeAMtoGetDealer = function (){
			$scope.resetParticipant();
			var temp=$scope.formData.amsecondselected.split("-");
			$scope.formData.amsecondselectedstr=temp[0];
			$scope.presenterselectedemail=temp[1];
			$scope.presenterselected=$scope.formData.amsecondselectedstr;
			if($scope.formData.roleselected == '7'){
				$scope.getparticipantinitiallist();
			}else{
				$scope.showdealerdiv='view';
				$scope.getDealerlistParticipator();	
			}
		}
		//==
		$scope.getDealerlistParticipator = function () {
			var fobj = {};
			fobj.funName = "getdealeruser";
			fobj.pid=$scope.formData.amsecondselectedstr;
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					$scope.dealerseconduserlist=res.item;
				} else {
					console.log("Error dealerseconduserlist")
				}
			})
		} 
		//==
        $scope.getAMlist = function () {
			

			var fobj = {};
			fobj.funName = "getamlist";
			fobj.role = "4";
			fobj.value=$scope.selectedrmlist;
				AppData.sendData($scope.pageurl, fobj, function (res) {
					if (res.cont) {
						$scope.amlistcheckbox= res.item;
						if($scope.amlistcheckbox.length>0){
							$scope.showparticipantareadiv='view';
						}
					} else {
						$scope.amlistcheckbox=[];
						console.log("Error changermcheckbox")
					}
				})
        }
        //==
        $scope.getDealerlist = function () {
			var fobj = {};
			fobj.funName = "getdealerlist";
			fobj.value=$scope.selectedamlist;
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					$scope.dealerlistcheckbox= res.item;
					if($scope.dealerlistcheckbox.length>0){
						$scope.showparticipantdealerdiv='view';
					}
				} else {
					$scope.dealerlistcheckbox=[];
					console.log("Error changeamcheckbox")
				}
			})
		}
		//==
		$scope.getuserlistzm = function () {
			var fobj = {};
			fobj.funName = "getzmuser";
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					$scope.zmuserlist=res.item;
					$scope.zmlistcheckbox=res.item;
				} else {
					console.log("Error zmuserlist")
				}
			})
		}
		
		//==Change the RM 
		$scope.changezmcheckbox = function (){
			$scope.amlistcheckbox =[];
			$scope.dealerlistcheckbox =[];
			$scope.dsclistcheckbox =[];
			//$scope.showparticipantregiondiv ='noview';
			$scope.showparticipantareadiv = 'noview';
			$scope.showparticipantdealerdiv = 'noview';
			$scope.showparticipantdscdiv = 'noview';
			
		
			
				$scope.selectedzmlist.push($scope.valueselectedtrainer);
			
			//var ter=JSON.stringify($scope.selectedzmlist);
			//==Database Call ====
			var fobj = {};
			fobj.funName = "getrmlist";
			fobj.role = "5";
			fobj.value = $scope.selectedzmlist;
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					$scope.rmlistcheckbox= res.item;
					if($scope.rmlistcheckbox.length>0){
						//$scope.showparticipantregiondiv='view';
					}
				} else {
					$scope.rmlistcheckbox=[];
					console.log("Error changezmcheckbox")
				}
			})
		}
		//==Change AM==
		$scope.changermcheckbox = function (rmuser){
			$scope.dealerlistcheckbox =[];
			$scope.dsclistcheckbox =[];
			$scope.showparticipantareadiv = 'noview';
			$scope.showparticipantdealerdiv = 'noview';
			$scope.showparticipantdscdiv = 'noview';
			$scope.showguestdiv = 'noview';
			var indexOfDay = $scope.selectedzmlist.indexOf(rmuser.value); 
			if(indexOfDay === -1){
				$scope.selectedrmlist.push(rmuser.value);
			}else{
				$scope.selectedrmlist.splice(indexOfDay, 1);
			}
			//var ter=JSON.stringify($scope.selectedrmlist);
			//==Database Call ====
			var fobj = {};
			fobj.funName = "getamlist";
			fobj.value = $scope.selectedrmlist;
			
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					$scope.amlistcheckbox= res.item;
					if($scope.amlistcheckbox.length>0){
						$scope.showparticipantareadiv='view';
					}
				} else {
					$scope.amlistcheckbox=[];
					console.log("Error changermcheckbox")
				}
			})
		}
		//==
		$scope.changeamcheckbox = function (amuser){
			$scope.dsclistcheckbox =[];
			$scope.showparticipantdealerdiv = 'noview';
			$scope.showparticipantdscdiv = 'noview';
			$scope.showguestdiv = 'noview';
			var indexOfDay = $scope.selectedamlist.indexOf(amuser.value); 
			if(indexOfDay === -1){
				$scope.selectedamlist.push(amuser.value);
			}else{
				$scope.selectedamlist.splice(indexOfDay, 1);
			}
			//var ter=JSON.stringify($scope.selectedamlist);
			//console.log("ter--->",ter);
			//==Database Call ====
			var fobj = {};
			fobj.funName = "getdealerlist";
			fobj.value = $scope.selectedamlist;
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					$scope.dealerlistcheckbox= res.item;
					if($scope.dealerlistcheckbox.length>0){
						$scope.showparticipantdealerdiv='view';
					}
				} else {
					$scope.dealerlistcheckbox=[];
					console.log("Error changeamcheckbox")
				}
			})
		}
		//==
		$scope.changedealercheckbox = function (dealeruser){
			$scope.showparticipantdscdiv = 'noview';
			$scope.showguestdiv = 'noview';
			var indexOfDay = $scope.selecteddealerlist.indexOf(dealeruser.value); 
			if(indexOfDay === -1){
				$scope.selecteddealerlist.push(dealeruser.value);
			}else{
				$scope.selecteddealerlist.splice(indexOfDay, 1);
			}
			//==Database Call ====
			var fobj = {};
			fobj.funName = "getdselist";
		//	fobj.typeid =$scope.formData.typeselected;
			fobj.typeid ='';
			fobj.value = $scope.selecteddealerlist;
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					$scope.dsclistcheckbox= res.item;
					 $scope.dsclistafterremoval = $scope.removeduplicates($scope.dsclistcheckbox,$scope.itemlist_result)
					if($scope.dsclistcheckbox.length>0){
						$scope.showparticipantdscdiv='view';
					}
				} else {
					$scope.dsclistcheckbox=[];
					console.log("Error changedealercheckbox")
				}
			})
		}

		//==getTrainerList==
		$scope.gettrainerlist = function () {
			var fobj = {};
			fobj.funName = "gettraineruser";
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					$scope.traineruserlist=res.item;
				} else {
					console.log("Error traineruserlist")
				}
			})
		}
		
		//==
		$scope.changeDealertogetDSC = function (){
			$scope.resetParticipant();
			if($scope.formData.roleselected == '14'){
				var temp=$scope.formData.dealersecondselected.split("-");
				$scope.formData.dealersecondselectedstr=temp[0];
				$scope.presenterselectedemail=temp[1];
				$scope.presenterselected=$scope.formData.amsecondselectedstr;
				$scope.getparticipantinitiallist();
			}else{
				$scope.showdealerdiv='view';
				$scope.getDealerlistParticipator();	
			}
		}
		//==
        $scope.getDSElist = function () {
			var fobj = {};
			fobj.funName = "getdselist";
			fobj.typeid =$scope.formData.typeselected;
			fobj.value = $scope.selecteddealerlist;
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					$scope.dsclistcheckbox= res.item;
					if($scope.dsclistcheckbox.length>0){
						$scope.showparticipantdscdiv='view';

					}
				} else {
					$scope.dsclistcheckbox=[];
					console.log("Error getDSElist")
				}
			})
		}
		//==
		$scope.resetParticipant = function (){
			$scope.zmlistcheckbox=[];
			$scope.rmlistcheckbox=[];
			$scope.amlistcheckbox=[];
			$scope.dealerlistcheckbox=[];
			$scope.dsclistcheckbox=[];

			$scope.selectedzmlist =[];
			$scope.selectedrmlist =[];		
			$scope.selectedamlist =[];										
			$scope.selecteddealerlist =[];


			$scope.zm=[];
			$scope.guestrmdata=[];
			$scope.guestamdata=[];

			$scope.guestzmmodel=[];
			$scope.guestrmmodel=[];
			$scope.guestammodel=[];


			$scope.showparticipantzonediv='noview';
			$scope.showparticipantregiondiv='noview';
			$scope.showparticipantareadiv='noview';
			$scope.showparticipantdealerdiv='noview';
			$scope.showparticipantdscdiv='noview';
			$scope.showguestdiv = 'noview';
		}
		//==
		$scope.getuserlistedit = function(itemlist,indexval){
			$scope.valueselectedtrainer=itemlist.organisercode;
			$scope.presenterselected=itemlist.organiser;
			$scope.fromtime=itemlist.fromdate;
			$scope.arritemlist=itemlist;
			$scope.indexval=indexval;
			$scope.idsend=itemlist.id;
			var fobj = {};
			fobj.funName = "trainingparticipantlist";
			fobj.id =$scope.idsend;
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					$scope.itemlist_result=res.item;
					
				} else {
					
					console.log("Error getuserlistedit")
				}
			})
		}
		//===
		$scope.removeduplicates = function(temp1,temp2){
			
			for (var i = 0; i < temp2.length; i++) {
				var temp2userid=temp2[i].userid;
				for(var j=0;j<temp1.length;j++){
					var temp1userid=temp1[j].userid;
					if(temp1userid == temp2userid){
						temp1.splice(j, 1);
					}else{
					}
				}
			}
			return temp1;
		}
		//==
		$scope.getguestzmlist = function(){
			$scope.guestzmdata=[];
			//==Database Call ====
			var fobj = {};
			fobj.funName = "ilearnuserlist";
			fobj.role ='4';
			fobj.userid = $scope.presenterselected;
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					$scope.showguestdivmodal='view';
					if($scope.itemlist_result.length>0){
						
						var getzm = $scope.removeduplicates(res.item,$scope.itemlist_result)
						for(var i=0;i<getzm.length;i++){
							var temp='';
							if(getzm[i].lname !=''){
								temp="-"+getzm[i].lname;
							}else{
								temp='';
							}
							$scope.guestzmdata.push({"label":getzm[i].fname+temp,"id":getzm[i].userid});
						}
					//	console.log("$scope.guestzmdata---->",$scope.guestzmdata)
					}else{
						for(var i=0;i<res.item.length;i++){
							var temp='';
							if(res.item[i].lname !=''){
								temp="-"+res.item[i].lname;
							}else{
								temp='';
							}
							$scope.guestzmdata.push({"label":res.item[i].fname+temp,"id":res.item[i].userid});
						}
					}
				} else {
					
				}
			})
		}
		//==
		$scope.getguestrmlist = function(){
			$scope.guestrmdata=[];
			//==Database Call ====
			var fobj = {};
			fobj.funName = "ilearnuserlist";
			fobj.role ='6';
			fobj.userid = $scope.presenterselected;
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
				//	console.log("res.item.length--->",res.item.length)
				if($scope.itemlist_result.length>0){
						
					var getzm = $scope.removeduplicates(res.item,$scope.itemlist_result)
					for(var i=0;i<getzm.length;i++){
						var temp='';
						if(getzm[i].lname !=''){
							temp="-"+getzm[i].lname;
						}else{
							temp='';
						}
						$scope.guestrmdata.push({"label":getzm[i].fname+temp,"id":getzm[i].userid});
					}
					
				}else{
					for(var i=0;i<res.item.length;i++){
						var temp='';
						if(res.item[i].lname !=''){
							 temp="-"+res.item[i].lname;
						}else{
							temp='';
						}
						$scope.guestrmdata.push({"label": res.item[i].fname+temp,"id":res.item[i].userid});
					}
				}
				} else {
				}
			})
		}
		//==
		$scope.getguestamlist = function(){
			//==Database Call ====
			$scope.guestamdata=[];
			var fobj = {};
			fobj.funName = "ilearnuserlist";
			fobj.role ='7';
			fobj.userid = $scope.presenterselected;
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					if($scope.itemlist_result.length>0){
						
						var getzm = $scope.removeduplicates(res.item,$scope.itemlist_result)
						for(var i=0;i<getzm.length;i++){
							var temp='';
							if(getzm[i].lname !=''){
								temp="-"+getzm[i].lname;
							}else{
								temp='';
							}
							$scope.guestamdata.push({"label":getzm[i].fname+temp,"id":getzm[i].userid});
						}
					}else{
					for(var i=0;i<res.item.length;i++){
						var temp='';
						if(res.item[i].lname !=''){
							 temp="-"+res.item[i].lname;
						}else{
							temp='';
						}
						$scope.guestamdata.push({"label": res.item[i].fname+temp,"id":res.item[i].userid});
					}
				}
				} else {
				
				}
			})
		}
		//==
		$scope.resetall = function (){

			$scope.formData.zmsecondselected =''; 
			$scope.formData.rmsecondselected ='';
			$scope.formData.amsecondselected =''; 
			$scope.formData.dealersecondselected  ='';
			$scope.formData.trainerselected ='';
			$scope.presenterselected='';
			$scope.presenterselectedemail='';
			$scope.formData.typeselected='';
			$scope.formData.description='';
			$scope.formData.sdate='';
			$scope.formData.starttimeselected='';
			$scope.formData.endtimeselected='';
			$scope.formData.roleselected='';
			$scope.formData.trainerselected='';
			$scope.formData.zmselected='';

			$scope.showrmdiv='noview';
			$scope.showamdiv='noview';
			$scope.showdealerdiv='noview';
			$scope.showguestdiv='noview';


			$scope.showparticipantzonediv='noview';
			$scope.showparticipantregiondiv='noview';
			$scope.showparticipantareadiv='noview';
			$scope.showparticipantdealerdiv='noview';
			$scope.showparticipantdscdiv='noview';
	
	
			$scope.selectedrmlist=[];
			$scope.selectedamlist=[];
			$scope.selectedzmlist=[];
			$scope.selecteddealerlist=[];
			$scope.selecteddsclist=[];
			$scope.selecteddsclistvalue=[];
			$scope.zmlistcheckbox=[];
			$scope.rmlistcheckbox=[];
			$scope.amlistcheckbox=[];
			$scope.dealerlistcheckbox=[];
			$scope.dsclistcheckbox=[];
			$scope.showguestdiv='';
			$scope.showguestdivmodal='';
			$scope.guestzmdata=[];
			$scope.guestrmdata=[];
			$scope.guestamdata=[];
			$scope.guestzmmodel=[];
			$scope.guestrmmodel=[];
			$scope.guestammodel=[];
			$scope.presenterselected='';
		}
		//==
		$scope.addSchedule = function () {
			$scope.clearErrorMsg();


			$scope.finallist=[];

			if($scope.selecteddsclist.length>0){
				for($i=0;$i<$scope.selecteddsclist.length;$i++){
					$scope.finallist.push($scope.selecteddsclist[$i]);
				}
			}

			if($scope.guestzmmodel.length>0){
				for($i=0;$i<$scope.guestzmmodel.length;$i++){
					$scope.finallist.push($scope.guestzmmodel[$i].id);
				}
			}
			if($scope.guestrmmodel.length>0){
				for($i=0;$i<$scope.guestrmmodel.length;$i++){
					$scope.finallist.push($scope.guestrmmodel[$i].id);
				}
			}
			if($scope.guestammodel.length>0){
				for($i=0;$i<$scope.guestammodel.length;$i++){
					$scope.finallist.push($scope.guestammodel[$i].id);
				}
			}
			
			$scope.ter='';
			$scope.ter=JSON.stringify($scope.finallist)
		
			var start_date=$scope.formData.sdate;
			var start_time=$scope.formData.starttimeselected;
			var end_time=$scope.formData.endtimeselected;
	
			$scope.startinsertvalue=start_date+' '+start_time;
			$scope.endinsertvalue=start_date+' '+end_time;
	
			
	
			var fobj = {};
			fobj.funName = "addtraining";
			fobj.userid = $scope.presenterselected;
			fobj.role = $scope.formData.roleselected;
			fobj.title = $scope.formData.typeselected;
			fobj.description = $scope.formData.description;
			fobj.fromdate = $scope.startinsertvalue;
			fobj.todate = $scope.endinsertvalue;
			fobj.typeid = $scope.formData.typeselected;
			fobj.dse=$scope.ter;
			
			
	
			if ($scope.fieldValidation()) {
				AppData.sendData($scope.pageurl, fobj, function (res) {
					if (res.cont) {
						$rootScope.modalShown = true;
						$rootScope.message = (res.mess);
						$scope.resetall();
						$scope.videoList();
						$scope.newschedule=false;
					} else {
						$rootScope.modalShown = true;
						$rootScope.message = (res.mess);
					}
			})
			}
		}
	
		//==
		$scope.gettimedisplay = function (){
			var quarterHours = ["00", "15", "30", "45"];
			$scope.starttimes = [];
			for(var i = 0; i < 24; i++){
				for(var j = 0; j < 4; j++){
					if(i<10){
						$scope.starttimes.push('0'+i + ":" + quarterHours[j]);
					}else{
						$scope.starttimes.push(i + ":" + quarterHours[j]);
					}
					
				}
			}
		}
		$scope.gettimedisplay();
		$scope.changestarttime = function (){
			$scope.endtimes =[];
			for(var i = 0; i < $scope.starttimes.length; i++){
				if($scope.formData.starttimeselected==$scope.starttimes[i]){
					$scope.endtimes =[];
				}else{
					$scope.endtimes.push($scope.starttimes[i]);
				}
			}
		}
		//==
		$scope.deleteRow = function (itemlist,indexval){
			$scope.formData = itemlist;
			$scope.selectedIndex = indexval;
			$scope.deleteFun();
		}
		//==
		$scope.deleteFun = function(){
			if($scope.selectedIndex != null){
				$rootScope.cofirmWindow = true;
				$rootScope.modalShown =true;
				$rootScope.message="Are you sure you want to delete?";
			}else{
				$rootScope.modalShown =true;
				$rootScope.message=$scope.pageData.errorMsg[0];
			}
		}
		
		$scope.$on("confirmDelete",function(){
			var fobj = {};
			fobj.funName = "deletetraining";
			fobj.id = $scope.formData.id;
			AppData.sendData($scope.pageurl,fobj,function(res){
				if(res.cont){
					$scope.traineruserlist();
					$rootScope.modalShown =true;
					$rootScope.cofirmWindow = false;
					$rootScope.message=(res.mess);
				}else{
					$rootScope.modalShown =true;
					$rootScope.message=(res.mess);
				}
			})
		})
		//==
	
		//==
		$scope.clearErrorMsg = function () {
			$scope.role_error = ' ';
			$scope.desc_error = ' ';
			$scope.sdate_error = ' ';
			$scope.edate_error = ' ';
			$scope.userid_error = ' ';
			$scope.dse_error = ' ';	
	
		}
		$scope.changedscheckbox = function (param) {
			//console.log("param---->",param)	
			
			var indexOfDay = $scope.selecteddsclist.indexOf(param.userid);
			if (indexOfDay === -1) {
				$scope.selecteddsclist.push(param.userid);
			} else {
				$scope.selecteddsclist.splice(indexOfDay, 1);
			}
			if($scope.selecteddsclist.length == 0){
				$scope.showguestdiv='noview';
			}else{
				$scope.getguestzmlist();
				$scope.getguestrmlist();
				$scope.getguestamlist();
				$scope.showguestdiv='view';
			}
			//console.log("$scope.selecteddsclist---->",$scope.selecteddsclist.length)
			$scope.ter = JSON.stringify($scope.selecteddsclist);
			//console.log("$scope.ter--->",$scope.ter)
		}
	
		//==
		$scope.changedscheckboxmodal = function (param) {
			//console.log("param---->",param)	
			
			var indexOfDay = $scope.selecteddsclist.indexOf(param.userid);
			///console.log("param----->indexOfDay",indexOfDay)
			if (indexOfDay === -1) {
				$scope.selecteddsclist.push(param.userid);
			} else {
				$scope.selecteddsclist.splice(indexOfDay, 1);
			}
			if($scope.selecteddsclist.length == 0){
				$scope.showguestdivmodal='noview';
			}else{
				$scope.getguestzmlist();
				$scope.getguestrmlist();
				$scope.getguestamlist();
				$scope.showguestdiv='view';
			}
			//console.log("$scope.selecteddsclist---->",$scope.selecteddsclist.length)
			$scope.ter = JSON.stringify($scope.selecteddsclist);
			//console.log("$scope.ter--->",$scope.ter)
		}
	
		$scope.view_function=function(param){
			$scope.resetall();
			$scope.formData.roleselected ='5';
			$scope.changeRole();
			if(param=='hide'){
				$scope.newschedule=true;
			}else{
				$scope.newschedule=false;	
			}
			
		}


		$scope.addparticiapantmodal=function(){
			$scope.resetParticipant();
			$scope.showparticipantregiondiv ='view';
			$scope.changezmcheckbox();
			//$scope.getuserlistzm();
				
		}
		$scope.add_participant=function(){
			if($scope.selecteddsclist.length>0){
				$scope.ter = JSON.stringify($scope.selecteddsclist);
				
				$scope.finallist=[];

			if($scope.selecteddsclist.length>0){
				for($i=0;$i<$scope.selecteddsclist.length;$i++){
					$scope.finallist.push($scope.selecteddsclist[$i]);
				}
			}

			if($scope.guestzmmodel.length>0){
				for($i=0;$i<$scope.guestzmmodel.length;$i++){
					$scope.finallist.push($scope.guestzmmodel[$i].id);
				}
			}
			if($scope.guestrmmodel.length>0){
				for($i=0;$i<$scope.guestrmmodel.length;$i++){
					$scope.finallist.push($scope.guestrmmodel[$i].id);
				}
			}
			if($scope.guestammodel.length>0){
				for($i=0;$i<$scope.guestammodel.length;$i++){
					$scope.finallist.push($scope.guestammodel[$i].id);
				}
			}
			
			var fobj = {};
			fobj.funName = "addparticipant";
			fobj.id = $scope.idsend;
			fobj.userid  = $scope.finallist; 
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					$rootScope.modalShown = true;
					$rootScope.message = (res.mess);
					$scope.resetall();
					$('#addexampleModal').modal('hide');
					$scope.getuserlistedit($scope.arritemlist,$scope.indexval)
					$scope.newschedule=false;
				} else {
					$rootScope.modalShown = true;
					$rootScope.message = (res.mess);
				}
		})
			}
			else{
				alert("DSE Selected is Error");
			}			
		}

		$scope.delete_participant=function(userid){
			var fobj = {};
			fobj.funName = "deleteparticipant";
			fobj.id=$scope.idsend;
			fobj.userid=userid;
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					$rootScope.modalShown = true;
					$rootScope.message = (res.mess);
				
					$scope.getuserlistedit($scope.arritemlist,$scope.indexval)
					$scope.newschedule=false;
				} else {
					$rootScope.modalShown = true;
					$rootScope.message = (res.mess);
				}
			})
		}
		//==
		$scope.fieldValidation = function () {	
			//alert("$scope.presenterselected--->"+$scope.presenterselected)
			$scope.presnter_error=($scope.presenterselected== undefined || $scope.presenterselected=='') ? true : false;
			$scope.role_error = ($scope.formData.typeselected== undefined || $scope.formData.typeselected=='') ? true : false;
			 $scope.desc_error = ($scope.formData.description == undefined || $scope.formData.description=='') ? true : false;
			$scope.sdate_error = ($scope.formData.sdate == undefined || $scope.formData.sdate=='') ? true : false;
			$scope.starttime_error = ($scope.formData.starttimeselected == undefined || $scope.formData.starttimeselected=='') ? true : false;
			$scope.endtime_error = ($scope.formData.endtimeselected == undefined || $scope.formData.endtimeselected=='') ? true : false;
			$scope.select_role_error = ($scope.formData.roleselected == undefined || $scope.formData.roleselected=='') ? true : false;		
			$scope.userid_error = ($scope.presenterselected == undefined || $scope.presenterselected=='') ? true : false;
			$scope.dse_error = ($scope.ter == undefined || $scope.ter=='' || $scope.ter == []) ? true : false;		
			if(($scope.role_error == false &&  $scope.desc_error == false && $scope.sdate_error == false && $scope.starttime_error ==false  && $scope.starttime_error ==false && $scope.endtime_error == false && $scope.userid_error == false && $scope.dse_error == false && $scope.presnter_error== false)){
				console.log("Validation Passed")
				return true;
			}else {
				console.log("Validation Failed")
				return false;
			}
		}
		//==
	  }
		})
		
		
	});
}); 

