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.selectedrmlist=[];
	$scope.selectedamlist=[];
	$scope.selectedzmlist=[];
	$scope.selecteddealerlist=[];
	$scope.selecteddsclist=[];

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

	$scope.endtimes =[];
	$scope.starttimes = [];

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


	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();
			$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 (){
			if($scope.presenterselected !=''){
				if($scope.formData.roleselected =='4'){
					//==get RM List
					//alert("$scope.presenterselectedemail--->"+$scope.presenterselectedemail)
					$scope.selectedzmlist.push($scope.presenterselectedemail);
					$scope.getRMlist();
					
				}else if($scope.formData.roleselected =='6'){
					//==get RM List
					$scope.selectedrmlist.push($scope.presenterselectedemail)
					$scope.getAMlist();
				}else if($scope.formData.roleselected =='7'){
					//==get AM List
					$scope.selectedamlist.push($scope.presenterselectedemail)
					$scope.getDealerlist();
				}else if($scope.formData.roleselected =='14'){
					//==get Dealer List
					$scope.selecteddealerlist.push($scope.presenterselectedemail)
					$scope.getDSElist();
				}else if($scope.formData.roleselected =='5'){
					//==get ZM List
					$scope.getuserlistzm();
				}else{
					console.log("Error in Getting Participant List")
				}
			}else{
				console.log("No Presenter Selected")
			}
		}
        //==
        $scope.getRMlist = function () {
			//==Database Call ====
			var fobj = {};
			fobj.funName = "getrmlist";
			fobj.role = "4";
			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';
			if($scope.formData.roleselected == '6'){
				var temp=$scope.formData.rmsecondselected.split("-");
				$scope.formData.rmsecondselectedstr=temp[0];
				$scope.presenterselectedemail=temp[1];
				$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();
			if($scope.formData.roleselected == '7'){
				var temp=$scope.formData.amsecondselected.split("-");
				$scope.formData.amsecondselectedstr=temp[0];
				$scope.presenterselectedemail=temp[1];
				$scope.presenterselected=$scope.formData.amsecondselectedstr;
				$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 (zmuser){
			var indexOfDay = $scope.selectedzmlist.indexOf(zmuser.value);
			if(indexOfDay === -1){
				$scope.selectedzmlist.push(zmuser.value);
			}else{
				$scope.selectedzmlist.splice(indexOfDay, 1);
			}
			//var ter=JSON.stringify($scope.selectedzmlist);
			//==Database Call ====
			var fobj = {};
			fobj.funName = "getrmlist";
			fobj.role = "4";
			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){
			//console.log("selectedzmlist--->",zmuser);
			//console.log("indexvalue--->",indexvalue)
			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){
		
			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){
			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.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 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.showparticipantzonediv='noview';
			$scope.showparticipantregiondiv='noview';
			$scope.showparticipantareadiv='noview';
			$scope.showparticipantdealerdiv='noview';
			$scope.showparticipantdscdiv='noview';
		}
		//==
		$scope.getuserlistedit = function(itemlist,indexval){
			$scope.idsend=itemlist.id;
			var fobj = {};
			fobj.funName = "trainingparticipantlist";
			fobj.id =$scope.idsend;
			AppData.sendData($scope.pageurl, fobj, function (res) {
				if (res.cont) {
					console.log("res--getuserlistedit--->",res.item)
				} else {
					
					console.log("Error getuserlistedit")
				}
			})
		}
		//==
		$scope.resetall = function (){
			$scope.formData.zmsecondselected =''; 
			$scope.formData.rmsecondselected ='';
			$scope.formData.amsecondselected =''; 
			$scope.formData.dealersecondselected  ='';
			$scope.formData.trainerselected ='';
			$scope.presenterselected='';
			$scope.presenterselectedemail='';
			$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.selectedrmlist=[];
			$scope.selectedamlist=[];
			$scope.selectedzmlist=[];
			$scope.selecteddealerlist=[];
			$scope.selecteddsclist=[];
	
			$scope.zmlistcheckbox=[];
			$scope.rmlistcheckbox=[];
			$scope.amlistcheckbox=[];
			$scope.dealerlistcheckbox=[];
			$scope.dsclistcheckbox=[];
		}
		//==
		$scope.addSchedule = function () {
			$scope.clearErrorMsg();
			
			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;
	
			//alert("$scope.startinsertvalue-->"+$scope.startinsertvalue)
			//alert("$scope.endtime-->"+$scope.endtime)
			//return false;
	
			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
			console.log(fobj);
			
	
			if ($scope.fieldValidation()) {
			
				AppData.sendData($scope.pageurl, fobj, function (res) {
					if (res.cont) {
						$rootScope.modalShown = true;
						$rootScope.message = (res.mess);
						$scope.videoList();
						$scope.newschedule=false;
					} else {
						$rootScope.modalShown = true;
						$rootScope.message = (res.mess);
					}
			})
			}
			
			// else{
			// 	alert("failed - " + $scope.fieldValidation());
			// }
		
			
		}
		$scope.fieldValidation = function () {
			
	
			$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)){
				return true;
			}else {
				return false;
			}
	
	
		}
		//==
		$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]);
					}
					
				}
			}
			//==
			//console.log($scope.starttimes)
		}
		$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]);
				}
			}
			//console.log("End Times -->",$scope.endtimes)
		}
		//==
		$scope.deleteRow = function (itemlist,indexval){
			$scope.formData = itemlist;
			console.log("$scope.formData.id----->",$scope.formData.id)
			$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) {	
	
			var indexOfDay = $scope.selecteddsclist.indexOf(param.value);
			if (indexOfDay === -1) {
				$scope.selecteddsclist.push(param.userid);
			} else {
				$scope.selecteddsclist.splice(indexOfDay, 1);
			}
			$scope.ter = JSON.stringify($scope.selecteddsclist);
			//console.log($scope.ter)
		}
	
	
		$scope.view_function=function(param){
			$scope.resetall();
			if(param=='hide'){
				$scope.newschedule=true;
			}else{
				$scope.newschedule=false;	
			}
			
		}
	  }
	  
	})
	


});
	
}); 

