text:
'use strict';

/* Directives */

angular.module('myApp.directives', ['ngCookies', 'blueimp.fileupload']).
  directive('appVersion', ['version', function(version) {
    return function(scope, elm, attrs) {
      elm.text(version);
    };
  }])
  .directive('ngEnter', function() {
	return function(scope, element, attrs) {
		element.bind("keydown keypress", function(event) {
			if(event.which === 13) {
				scope.$apply(function(){
					scope.$eval(attrs.ngEnter);
				});

				event.preventDefault();
			}
		});
	};
  })
  .directive('hotelRating', function () {  //RATING DIRECTIVE
	return {
		restrict: 'A',
		template: '
' +
					'
' +
						'\u2605' +
					'
' +
				  '
',
		scope: {
			ratingValue: '=',
			max: '='
		},
		link: function (scope, elem, attrs) {
			console.log(scope.ratingValue);
			var updateStars = function(){
				scope.stars = [];
				for(var i = 0; i < scope.max; i++) {
					scope.stars.push({filled: i < scope.ratingValue});
				}
			};
			scope.$watch('ratingValue', function(oldVal, newVal) {
				console.log(scope.ratingValue);
				updateStars();
			});
		}
	}
  })
  .directive('bookingWidget', ['$location', 'Hotel', '$cookieStore', function ($location, Hotel, $cookieStore) { //BOOKING WIDGET DIRECTIVE
	return {
		restrict: 'A',
		scope: {
			hotel: '='
		},
		link: function (scope, elm, attrs) {
			//INITIALIZATION
			scope.newsletterData = Hotel.AddNewsletter(scope, 'newsletterData','Midtown');
			scope.startDate = new Date();
			scope.endDate = new Date(scope.startDate);
			scope.endDate.setDate(scope.endDate.getDate() + 1);
			scope.dateOptions = {'year-format': "'yy'", 'starting-day': 1};

			scope.today = function() {
				scope.dt = new Date();
				var tempDate = new Date(scope.startDate);
				tempDate.setDate(scope.startDate.getDate() + 1);

				scope.endDateBound = tempDate;
			};
			scope.today();

			scope.clear = function () {
				scope.dt = null;
			};

			//DISABLE WEEKEND SELECTION
			scope.disabled = function(date, mode) {
				return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
			};

			//TOGGLE MIN DATE
			scope.toggleMin = function() {
				scope.minDate = ( scope.minDate ) ? null : new Date();
			};
			scope.toggleMin();

			scope.open = function() {
				$timeout(function() {
				  scope.opened = true;
				});
			};

			//WATCH START DATE
			scope.$watch('startDate', function(newVal, oldVal) {
				if(newVal)
				{
					var tempDate = new Date(scope.startDate);
					tempDate.setDate(scope.startDate.getDate() + 1);
					scope.endDateBound = tempDate;

					if (scope.startDate >= scope.endDate) {
						scope.endDate = tempDate;
					}

					//scope.$emit('updateStartDate', val);
					scope.startBoxHid = true;
				}
				else
				{
				}
			},true);

			//WATCH END DATE
			scope.$watch('endDate', function(val) {
				scope.endBoxHid = true;
				//scope.$emit('updateEndDate', val);
			});

			//CONVERT DATE TO STRING OR OBJECT
			scope.dateToYMD = function (date, format) {
				var weekday = new Array(7);
				weekday[0] = "Sunday";
				weekday[1] = "Monday";
				weekday[2] = "Tuesday";
				weekday[3] = "Wednesday";
				weekday[4] = "Thursday";
				weekday[5] = "Friday";
				weekday[6] = "Saturday";

				var monthName = new Array(12);
				monthName[0] = "January";
				monthName[1] = "February";
				monthName[2] = "March";
				monthName[3] = "April";
				monthName[4] = "May";
				monthName[5] = "June";
				monthName[6] = "July";
				monthName[7] = "August";
				monthName[8] = "September";
				monthName[9] = "October";
				monthName[10] = "November";
				monthName[11] = "December";

				var d = date.getDate();
				var m = date.getMonth() + 1;
				var y = date.getFullYear();
				var day = date.getDay();
				if (format == "String")
					return '' + y + '-' + (m<=9 ? '0' + m : m) + '-' + (d <= 9 ? '0' + d : d);
				else if (format == "Object")
					return {
						date: (d <= 9 ? '0' + d : d),
						month: (monthName[m-1]).substring(0,3),
						year: y,
						day: (weekday[day]).substring(0,3),
						weekday: (day == 0 || day == 6 ? true : false) }
			}

			//SUBMIT WIDGET FORM
			scope.searchRoom = function(){
				var jml = 0;
				$.each(scope.newsletterData, function(index, item){
					if(item.email == scope.email){
						console.log(item.email);
						jml++
					}
				});
				console.log(jml);
				if(jml==0){
					scope.newsletterData.add({name: scope.name, email: scope.email});
				}
				console.log("success!");
				$location.path("/reservation/" + scope.dateToYMD(scope.startDate,"String") + "/" + scope.dateToYMD(scope.endDate,"String"));
			}

			//HANDLE BOOKING WIDGET TOGGLE
			scope.showhideWidget = function() {
				if($("#widget").hasClass('widget-show'))
				  {
					$("#widget").animate({ left: '-220px' });
					$("#widget").removeClass('widget-show');
					$("#widget").addClass('widget-hide');
					scope.startBoxHid = true;
					$(".button-icon").css('-webkit-transform', 'rotate(0deg)');
				}
				else if($("#widget").hasClass('widget-hide'))
				  {
					$("#widget").animate({ left: '0px' });
					$("#widget").removeClass('widget-hide');
					$("#widget").addClass('widget-show');
					$(".button-icon").css('-webkit-transform', 'rotate(180deg)');
				  }
			};

			//DESTROY COOKIE
			scope.destroyCookie = function() {
				$cookieStore.remove('guestInfo');
				$cookieStore.remove('step');
				for(var i = 0; i < scope.hotel.rooms.length; i++){
					$cookieStore.remove(scope.hotel.rooms[i].name);
				}
				$cookieStore.remove('checkIn');
				$cookieStore.remove('checkOut');
			}

			scope.$watch('hotel', function(e, val) {
				scope.destroyCookie();
			})
		}
	}
  }])
  .directive('reservation', ['BookingService', '$location', '$cookieStore', '$timeout', function(BookingService, $location, $cookieStore, $timeout){ //RESERVATION DIRECTIVE
	return{
		restrict: 'A',
		scope: {
			hotel: '=',
			checkInDate: '=',
			checkOutDate: '='
		},
		link: function(scope, elm, attrs) {
			scope.guestInfo = {};
			scope.arrTimes = [{name: '12.00 PM'},{name: '01.00 PM'}, {name: '02.00 PM'},{name: '03.00 PM'}, {name: '04.00 PM'}, {name: '05.00 PM' }, {name: '06.00 PM' }, {name: '07.00 PM'} ,{name: '08.00 PM'}, {name: '09.00 PM'}, {name: '10.00 PM'}, {name: '11.00 PM'}];
			scope.hears = [{name: 'Internet'},{name: 'Magazine'}, {name: 'Newspaper'},{name: 'Radio'}, {name: 'Television'}, {name: 'Facebook' }, {name: 'Google' }];
			scope.cards = [{name:'Visa', uri:'img/demo-hotel/card/visa.jpg'}, {name:'Mastercard', uri:'img/demo-hotel/card/mastercard.jpg'}, {name:'JCB', uri:'img/demo-hotel/card/JCB.jpg'}];
			scope.error = true;
			scope.roomReserve = [];
			scope.startBoxHid = true;
			scope.endBoxHid = true;
			scope.steps = ['room', 'guest', 'confirm'];
			scope.step = 0;
			scope.limit = 999;
			var notifModal = $('#successModal');
			var listOfAvailableRoom = [];
			scope.reservationData = BookingService.addBooking(scope, 'reservationData', 'Midtown');
			BookingService.addOccupied(scope, 'roomData', 'Midtown');
			scope.dateOptions = {'year-format': "'yy'", 'starting-day': 1};
			if(angular.isUndefined($cookieStore.get('step'))){
				$cookieStore.put('step', scope.step);
			}
			if(!angular.isUndefined($cookieStore.get('checkIn'))){
				scope.checkInDate = new Date($cookieStore.get('checkIn'));
			}
			if(!angular.isUndefined($cookieStore.get('checkOut'))){
				scope.checkOutDate = new Date($cookieStore.get('checkOut'));

			}

			scope.clear = function () {
				scope.dt = null;
			};
			$('#loading').css('display','block');
			//CONVERT DATE TO STRING OR OBJECT FUNCTION
			scope.dateToYMD = function (date, format) {
				var weekday = new Array(7);
				weekday[0] = "Sunday";
				weekday[1] = "Monday";
				weekday[2] = "Tuesday";
				weekday[3] = "Wednesday";
				weekday[4] = "Thursday";
				weekday[5] = "Friday";
				weekday[6] = "Saturday";

				var monthName = new Array(12);
				monthName[0] = "January";
				monthName[1] = "February";
				monthName[2] = "March";
				monthName[3] = "April";
				monthName[4] = "May";
				monthName[5] = "June";
				monthName[6] = "July";
				monthName[7] = "August";
				monthName[8] = "September";
				monthName[9] = "October";
				monthName[10] = "November";
				monthName[11] = "December";

				var d = date.getDate();
				var m = date.getMonth() + 1;
				var y = date.getFullYear();
				var day = date.getDay();
				if (format == "String")
					return '' + y + '-' + (m<=9 ? '0' + m : m) + '-' + (d <= 9 ? '0' + d : d);
				else if (format == "Object")
					return {
						date: (d <= 9 ? '0' + d : d),
						month: (monthName[m-1]),
						year: y,
						day: (weekday[day]),
						weekday: (day == 0 || day == 6 ? true : false) }
			}

			scope.startDate = scope.dateToYMD(scope.checkInDate, 'Object');
			scope.endDate = scope.dateToYMD(scope.checkOutDate, 'Object');

			//CHECK FIRST STEP?
			scope.isFirstStep = function() {
				return scope.step === 0;
			};

			//CHECK LAST STEP?
			scope.isLastStep = function() {
				return scope.step === (scope.steps.length - 1);
			};

			//CHECK CURRENT STEP?
			scope.isCurrentStep = function(step) {
				return scope.step === step;
			};

			//SET CURRENT STEP
			scope.setCurrentStep = function(step) {
				scope.step = step;
			};

			//GET CURRENT STEP
			scope.getCurrentStep = function() {
				return scope.steps[scope.step];
			};

			//GET NEXT BUTTON LABEL
			scope.getNextLabel = function() {
				return (scope.isLastStep()) ? 'Submit' : 'Next';
			};

			//HANDLE PREVIOUS CLICK
			scope.handlePrevious = function() {
				window.scrollTo(0,0);
				if(scope.step == 1){
					scope.guestInfo = {
						firstName: scope.form.firstName.$modelValue,
						lastName: scope.form.lastName.$modelValue,
						email: scope.form.email.$modelValue,
						contactNumber : scope.form.contactNumber.$modelValue,
						organization: scope.form.organization.$modelValue,
						addressLine1: scope.form.address1.$modelValue,
						addressLine2: scope.form.address2.$modelValue,
						city: scope.form.city.$modelValue,
						state: scope.form.state.$modelValue,
						country: scope.form.country.$modelValue,
						postCode: scope.form.postcode.$modelValue,
						arrivalTime: scope.form.arrTime.$modelValue,
						loyaltyID: scope.form.loyaltyID.$modelValue,
						comment: scope.form.comment.$modelValue,
						cardType: scope.form.cardType.$modelValue,
						cardNumber: scope.form.cardNumber.$modelValue,
						cardCCV: scope.form.cardCCV.$modelValue,
						cardUser: scope.form.cardUser.$modelValue
					}
					$cookieStore.put('guestInfo', scope.guestInfo);
				}
				scope.step -= (scope.isFirstStep()) ? 0 : 1;
				if(scope.step==0) {
					$('#loading').css('display','none');
					scope.isError(1, true);
				}else if(scope.step==1){
				  scope.formRestore();
				  scope.isError(2, true);
				}
				$cookieStore.put('step', scope.step);
			};

			//HANDLE NEXT CLICK
			scope.handleNext = function(dismiss) {
				window.scrollTo(0,0);
				if(scope.isLastStep()) {
				  scope.formBook();
				} else {
				  if(scope.step == 1){
					scope.guestInfo = {
						firstName: scope.form.firstName.$modelValue,
						lastName: scope.form.lastName.$modelValue,
						email: scope.form.email.$modelValue,
						contactNumber : scope.form.contactNumber.$modelValue,
						organization: scope.form.organization.$modelValue,
						addressLine1: scope.form.address1.$modelValue,
						addressLine2: scope.form.address2.$modelValue,
						city: scope.form.city.$modelValue,
						state: scope.form.state.$modelValue,
						country: scope.form.country.$modelValue,
						postCode: scope.form.postcode.$modelValue,
						arrivalTime: scope.form.arrTime.$modelValue,
						loyaltyID: scope.form.loyaltyID.$modelValue,
						comment: scope.form.comment.$modelValue,
						cardType: scope.form.cardType.$modelValue,
						cardNumber: scope.form.cardNumber.$modelValue,
						cardCCV: scope.form.cardCCV.$modelValue,
						cardUser: scope.form.cardUser.$modelValue
					}
					$cookieStore.put('guestInfo', scope.guestInfo);
				  }
				  if(scope.step == 0){
					scope.RNReserve();
					for(var i = 0; i< scope.hotel.rooms.length; i++){
						$cookieStore.put(scope.hotel.rooms[i].name, scope.roomReserve[scope.hotel.rooms[i].name]);
					}
				  }
				  scope.step += 1;
				  $cookieStore.put('step', scope.step);
				  if(scope.step == 1){
					scope.formRestore();
					scope.isError(2,true);
				  } else {
					console.log("last");
					scope.priceCount();
					scope.error = false;
				  }
				}
			};

			//DISABLE WEEKEND SELECTION
			scope.disabled = function(date, mode) {
				return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
			};

			//TOGGLE MIN DATE
			scope.toggleMin = function() {
				scope.minDate = new Date();
				console.log(scope.minDate);
			};
			scope.toggleMin();

			scope.open = function() {
				$timeout(function() {
				  scope.opened = true;
				});
			};

			//WATCH HOTEL
			scope.$watch('hotel', function() {
				showAvailableRoomJSON();
				if($cookieStore.get('checkIn')){
					console.log(scope.dateToYMD(scope.checkInDate, 'String') == $cookieStore.get('checkIn') && scope.dateToYMD(scope.checkOutDate, 'String') == $cookieStore.get('checkOut'));
					if(scope.dateToYMD(scope.checkInDate, 'String') == $cookieStore.get('checkIn') && scope.dateToYMD(scope.checkOutDate, 'String') == $cookieStore.get('checkOut')){
						for(var i = 0; i < scope.hotel.rooms.length; i++){
							var roomNumbers = [];
							roomNumbers = scope.roomReserve[scope.hotel.rooms[i].name].roomNumber;
							if($cookieStore.get(scope.hotel.rooms[i].name)){
								scope.roomReserve[scope.hotel.rooms[i].name] = $cookieStore.get(scope.hotel.rooms[i].name);
								scope.roomReserve[scope.hotel.rooms[i].name].num  = scope.roomReserve[scope.hotel.rooms[i].name].numbers[scope.roomReserve[scope.hotel.rooms[i].name].num.number]
								scope.roomReserve[scope.hotel.rooms[i].name].roomNumber = roomNumbers;
							}
						}
					}
				}
				$cookieStore.put('checkIn', scope.dateToYMD(scope.checkInDate, 'String'));
				$cookieStore.put('checkOut', scope.dateToYMD(scope.checkOutDate, 'String'));

				if($cookieStore.get('step') == 0) {
					scope.isError(1,true);
				}
				scope.RNReserve();
			});

			//WATCH CHECK IN DATE (still error)
			scope.$watch('checkInDate', function(){
				scope.startBoxHid = true;
				$('#startPopUpBox-reserv').css('display', 'none');
				var tempDate = new Date(scope.checkInDate);
				tempDate.setDate(scope.checkInDate.getDate() + 1);
				scope.endDateBound = tempDate;
				if (scope.checkInDate >= scope.checkOutDate) {
					scope.checkOutDate = tempDate;
				}
				//showAvailableRoomJSON();
			  }, true);

			//WATCH CHECK OUT DATE (still error)
		    scope.$watch('checkOutDate', function(){
				scope.endBoxHid = true;
				$('#endPopUpBox-reserv').css('display', 'none');
				//showAvailableRoomJSON();
		    });

			//CHECK IN DATE CHANGE
			scope.checkInDateChange = function(){
				$timeout(function(){
					scope.startBoxHid = true;
					$('#startPopUpBox-reserv').css('display', 'none');
					scope.checkInDate = new Date($('#checkInDate').val());
					scope.checkOutDate = new Date($('#checkOutDate').val());
					$cookieStore.put('checkIn', scope.dateToYMD(scope.checkInDate, 'String'));
					$cookieStore.put('checkOut', scope.dateToYMD(scope.checkOutDate, 'String'));

					console.log(scope.dateToYMD(scope.checkOutDate, 'String'));
					scope.limit++;
					showAvailableRoomJSON();
					for(var i=0; i< scope.hotel.rooms.length; i++) {
						$cookieStore.put(scope.hotel.rooms[i].name, scope.roomReserve[scope.hotel.rooms[i].name]);
					}
					var step = $cookieStore.get('step');
					if(step == 0) {
						scope.isError(1,true);
					}
				});
			}

			//CHECK OUT DATE CHANGE
			scope.checkOutDateChange = function(){
				$timeout(function(){
					scope.endBoxHid = true;
					$('#endPopUpBox-reserv').css('display', 'none');
					scope.checkInDate = new Date($('#checkInDate').val());
					scope.checkOutDate = new Date($('#checkOutDate').val());
					$cookieStore.put('checkIn', scope.dateToYMD(scope.checkInDate, 'String'));
					$cookieStore.put('checkOut', scope.dateToYMD(scope.checkOutDate, 'String'));

					console.log(scope.dateToYMD(scope.checkOutDate, 'String'));
					scope.limit++;
					showAvailableRoomJSON();
					for(var i=0; i< scope.hotel.rooms.length; i++) {
						$cookieStore.put(scope.hotel.rooms[i].name, scope.roomReserve[scope.hotel.rooms[i].name]);
					}
					var step = $cookieStore.get('step');
					if(step == 0) {
						scope.isError(1,true);
					}
				});
			}

			//HANDLE NUMBER OF ROOM TO BOOK CHANGE
			scope.roomReserveChange = function() {
				for(var i=0; i< scope.hotel.rooms.length; i++) {
					$cookieStore.put(scope.hotel.rooms[i].name, scope.roomReserve[scope.hotel.rooms[i].name]);
				}
				scope.isError(1,true);
			}

			//HANDLE FORM CHANGE
			scope.formChange = function() {
				console.log("yeah");
				scope.guestInfo = {
					firstName: scope.form.firstName.$modelValue,
					lastName: scope.form.lastName.$modelValue,
					email: scope.form.email.$modelValue,
					contactNumber : scope.form.contactNumber.$modelValue,
					organization: scope.form.organization.$modelValue,
					addressLine1: scope.form.address1.$modelValue,
					addressLine2: scope.form.address2.$modelValue,
					city: scope.form.city.$modelValue,
					state: scope.form.state.$modelValue,
					country: scope.form.country.$modelValue,
					postCode: scope.form.postcode.$modelValue,
					arrivalTime: scope.form.arrTime.$modelValue,
					loyaltyID: scope.form.loyaltyID.$modelValue,
					comment: scope.form.comment.$modelValue,
					cardType: scope.form.cardType.$modelValue,
					cardNumber: scope.form.cardNumber.$modelValue,
					cardCCV: scope.form.cardCCV.$modelValue,
					cardUser: scope.form.cardUser.$modelValue
				}
				$cookieStore.put('guestInfo', scope.guestInfo);
				scope.isError(2,true);
			}

			//HANDLE FORM RESTORATION
			scope.formRestore = function() {
				scope.firstName = scope.guestInfo.firstName;
				scope.lastName = scope.guestInfo.lastName;
				scope.email = scope.guestInfo.email;
				scope.contactNumber = scope.guestInfo.contactNumber;
				scope.organization = scope.guestInfo.organization;
				scope.address1 = scope.guestInfo.addressLine1;
				scope.address2 = scope.guestInfo.addressLine2;
				scope.city = scope.guestInfo.city;
				scope.state = scope.guestInfo.state;
				scope.country = scope.guestInfo.country;
				scope.postcode = scope.guestInfo.postCode;
				if(!angular.isUndefined(scope.guestInfo.arrivalTime)){
					for(var i = 0; i< scope.arrTimes.length; i++){
						if(scope.arrTimes[i].name == scope.guestInfo.arrivalTime.name){
							scope.arrTime = scope.arrTimes[i];
						}
					}
				}
				scope.loyaltyID = scope.guestInfo.loyaltyID;
				scope.comment = scope.guestInfo.comment;
				if(!angular.isUndefined(scope.guestInfo.cardType)){
					for(var i = 0; i< scope.cards.length; i++){
						if(scope.cards[i].name == scope.guestInfo.cardType.name){
							scope.cardType = scope.cards[i];
						}
					}
					console.log(scope.cardType);
				}
				scope.cardNumber = scope.guestInfo.cardNumber;
				scope.cardCCV = scope.guestInfo.cardCCV;
				scope.cardUser = scope.guestInfo.cardUser;
				console.log("MASUK RESTORE");
			}

			//INITIALIZATION FUNCTION
			var init = function() {
				for (var i = 0; i < scope.hotel.rooms.length; i++) {
					listOfAvailableRoom[scope.hotel.rooms[i].name] = [];
					scope.roomReserve[scope.hotel.rooms[i].name] = {num: {number: 0}, max: 0, numbers: [], roomNumber: [], roomName: scope.hotel.rooms[i].name, RNReserve: []};
				};
			};

			//GET AVAILABLE ROOMS
			var showAvailableRoomJSON = function () {
				$('#loading').css('display','block');
				init();
				scope.numOfNight = (scope.checkOutDate - scope.checkInDate) / 86400000;
				console.log("masuk sini");
				$.each(scope.hotel.roomData, function(index, roomItem) {
					var roomAvailable = true;

					// CHECK IF CHECKIN - CHECKOUT RANGE CONTAIN OCCUPIED DATE
					if(roomItem.occuDate)
					{
						//console.log(roomItem.occuDate.length);
						$.each(roomItem.occuDate, function(index, occupiedDateStr) {
							var occupiedDate = new Date(occupiedDateStr.date);

							if (occupiedDate >= scope.checkInDate && occupiedDate < scope.checkOutDate) {
								roomAvailable = false;
								return false;
							}
						})
					}

					if (roomAvailable) {
						listOfAvailableRoom[roomItem.roomType].push(roomItem.roomId);
						scope.roomReserve[roomItem.roomType].max++;
						scope.roomReserve[roomItem.roomType].roomNumber.push({number: index+1});
					}
				});
				for(var i = 0; i< scope.hotel.rooms.length; i++) {
					for(var j = 0; j <= scope.roomReserve[scope.hotel.rooms[i].name].max; j++) {
						scope.roomReserve[scope.hotel.rooms[i].name].numbers.push({number: j});
					}
					scope.roomReserve[scope.hotel.rooms[i].name].num = scope.roomReserve[scope.hotel.rooms[i].name].numbers[0];
				}
				scope.listOfAvailableRoom = listOfAvailableRoom;
				$timeout(function(){
					$('#loading').css('display','none');
				},1000);
			}

			//GET ROOM NUMBER TO RESERVE
			scope.RNReserve = function() {
				for(var i = 0; i< scope.hotel.rooms.length; i++) {
					scope.roomReserve[scope.hotel.rooms[i].name].RNReserve = [];
					console.log(scope.roomReserve[scope.hotel.rooms[i].name].num.number);
					for(var j = 0; j < scope.roomReserve[scope.hotel.rooms[i].name].num.number; j++) {
						scope.roomReserve[scope.hotel.rooms[i].name].RNReserve.push({number: scope.roomReserve[scope.hotel.rooms[i].name].roomNumber[j].number});
					}
				}
			}

			//COUNT TOTAL CHARGE
			scope.priceCount = function() {
				scope.totalCharge = 0;
				for(var i = 0; i< scope.hotel.rooms.length; i++) {
					scope.totalCharge = scope.totalCharge + (scope.roomReserve[scope.hotel.rooms[i].name].num.number * parseInt(scope.hotel.rooms[i].fullRate * scope.numOfNight));
					console.log(scope.totalCharge);
				}
			}

			//HANDLE NEXT OR SUBMIT BUTTON ERROR
			scope.isError = function(step, bool) {
				if(step == 1 && bool) {
					var errorJumlah = 0;
					for(var i = 0; i < scope.hotel.rooms.length; i++){
						if(scope.roomReserve[scope.hotel.rooms[i].name]){
							errorJumlah = errorJumlah + scope.roomReserve[scope.hotel.rooms[i].name].num.number;
						}
					}
					if(errorJumlah == 0){
						scope.error = true;
					}else {
						scope.error = false;
					}
				} else if(step == 2 && bool){
					//console.log("ERRORNYAAAA " + (angular.isUndefined(scope.guestInfo.firstName) || angular.isUndefined(scope.guestInfo.lastName) || angular.isUndefined(scope.guestInfo.email) || angular.isUndefined(scope.guestInfo.contactNumber) || angular.isUndefined(scope.guestInfo.addressLine1) || angular.isUndefined(scope.guestInfo.city) || angular.isUndefined(scope.guestInfo.country) || angular.isUndefined(scope.guestInfo.postCode) || angular.isUndefined(scope.guestInfo.cardType) || angular.isUndefined(scope.guestInfo.cardNumber) || angular.isUndefined(scope.guestInfo.cardCCV) || angular.isUndefined(scope.guestInfo.cardUser)));
					if(angular.isUndefined(scope.guestInfo.firstName) || angular.isUndefined(scope.guestInfo.lastName) || angular.isUndefined(scope.guestInfo.email) || angular.isUndefined(scope.guestInfo.contactNumber) || angular.isUndefined(scope.guestInfo.addressLine1) || angular.isUndefined(scope.guestInfo.city) || angular.isUndefined(scope.guestInfo.country) || angular.isUndefined(scope.guestInfo.postCode) || angular.isUndefined(scope.guestInfo.cardType) || angular.isUndefined(scope.guestInfo.cardNumber) || angular.isUndefined(scope.guestInfo.cardCCV) || angular.isUndefined(scope.guestInfo.cardUser)) {
						scope.error = true;
					} else {
						$timeout(function() {
							if(scope.form.firstName.$valid && scope.form.lastName.$valid && scope.form.email.$valid && scope.form.contactNumber.$valid && scope.form.address1.$valid && scope.form.city.$valid && scope.form.country.$valid && scope.form.postcode.$valid && scope.form.cardNumber.$valid && scope.form.cardCCV.$valid && scope.form.cardUser.$valid){
								console.log('gak error');
								scope.error = false;
							}
							else{
								scope.error = true;
							}
						});

					}
				} else if(step == 2 && !bool) {
					scope.error = true;
				}
			};

			Array.prototype.indexOfRoomId = function(id) {
				for (var i = 0; i < this.length; i++)
					if (this[i].roomId === id)
						return i;
				return -1;
			}

			//BOOKING FUNCTION
			scope.formBook = function() {
				scope.roomNumber = [];
				var lastId = 0;
				$.each(scope.hotel.bookingData, function(index, roomItem) {
					lastId = roomItem.id;
				});

				for(var i = 0; i< scope.hotel.rooms.length; i++){
					if(scope.roomReserve[scope.hotel.rooms[i].name].num.number != 0) {
						for(var j = 0; j< scope.roomReserve[scope.hotel.rooms[i].name].num.number; j++){
							scope.roomNumber.push({number: scope.roomReserve[scope.hotel.rooms[i].name].RNReserve[j].number});
						}
					}
				}

				console.log(scope.roomNumber);

				//console.log(scope.roomData);
				for(var i = 0; i < scope.roomData.length; i++){
					for(var j = 0; j < scope.roomNumber.length; j++){
						console.log(scope.roomData[i].roomId == scope.roomNumber[j].number);
						if(scope.roomData[i].roomId == scope.roomNumber[j].number){
							var tempDate = new Date();
							tempDate.setDate(scope.checkInDate.getDate());
							console.log(scope.roomData[i].roomId);

							var id = scope.roomData.indexOfRoomId(scope.roomData[i].roomId);
							scope.occu = BookingService.addOccupiedById(scope, 'occu', 'Midtown', id);
							console.log(tempDate);

							while(scope.dateToYMD(tempDate, 'String') != scope.dateToYMD(scope.checkOutDate, 'String')){
								scope.occu.add({date: scope.dateToYMD(tempDate, 'String')});
								tempDate.setDate(tempDate.getDate() + 1);
							}
						}
					}
				}
				scope.reservationData.add({
					id: lastId+1,
					roomNumber: scope.roomNumber,
					bookingDate: scope.dateToYMD(new Date(), 'String'),
					startDate: scope.dateToYMD(scope.checkInDate, 'String'),
					endDate: scope.dateToYMD(scope.checkOutDate, 'String'),
					firstName: scope.guestInfo.firstName,
					lastName: scope.guestInfo.lastName,
					email: scope.guestInfo.email,
					contactNumber: scope.guestInfo.contactNumber,
					organization: scope.guestInfo.organization,
					addressLine1: scope.guestInfo.addressLine1,
					addressLine2: scope.guestInfo.addressLine1,
					city: scope.guestInfo.city,
					state: scope.guestInfo.state,
					country: scope.guestInfo.country,
					postCode: scope.guestInfo.postCode,
					arrivalTime: scope.guestInfo.arrivalTime,
					loyaltyID: scope.guestInfo.loyaltyID,
					comment: scope.guestInfo.comment,
					receive: scope.guestInfo.receive,
					hear: scope.guestInfo.hear,
					cardType: scope.guestInfo.cardType,
					cardNumber: scope.guestInfo.cardNumber,
					cardCCV: scope.guestInfo.cardCCV,
					cardUser: scope.guestInfo.cardUser,
					totalCharge: scope.totalCharge,
					status: "not payed"
					}, function(error){
						if(!error) {
							notifModal.modal('show');
							scope.destroyCookie();
						}
				});
			}

			notifModal.on('hidden.bs.modal', function () {
				$location.path('/home');
				scope.$apply();
			});

			scope.closeNotifBooking = function() {
				notifModal.modal('toggle');
			};

			//DESTROY COOKIE
			scope.destroyCookie = function() {
				$cookieStore.remove('guestInfo');
				$cookieStore.remove('step');
				$cookieStore.remove('checkIn');
				$cookieStore.remove('checkOut');
				for(var i = 0; i < scope.hotel.rooms.length; i++){
					$cookieStore.remove(scope.hotel.rooms[i].name);
				}

			}

			//HANDLE PAGE REFRESH
			if($cookieStore.get('step')){
				scope.setCurrentStep($cookieStore.get('step'));
				scope.guestInfo = $cookieStore.get('guestInfo');
				console.log($cookieStore.get('guestInfo'));
				scope.formRestore();
				if($cookieStore.get('step') == 1){
					scope.isError(2,true);
				} else if($cookieStore.get('step') == 2){
					scope.error = false;
				}

			}

			scope.startBoxHidChange = function() {
				console.log(scope.startBoxHid);
				scope.startBoxHid = !scope.startBoxHid;
				console.log(scope.startBoxHid);
				if(scope.startBoxHid){
					$('#startPopUpBox-reserv').css('display', 'none');
				} else {
					$('#startPopUpBox-reserv').css('display', 'block');
				}

			}

			scope.endBoxHidChange = function() {
				scope.endBoxHid = !scope.endBoxHid;
				if(scope.endBoxHid){
					$('#endPopUpBox-reserv').css('display', 'none');
				} else {
					$('#endPopUpBox-reserv').css('display', 'block');
				}
			}
		}
	}
  }])
  .directive('hotelInformation', ['$location', '$cookieStore', '$timeout', 'Hotel', function($location, $cookieStore, $timeout, Hotel){
	return{
		restrict: 'A',
		scope: {
			hotel: '='
		},
		link: function(scope, elm, attrs){
			scope.hotelNameEditShow = false;
			scope.addressEditShow = false;
			scope.emailEditShow = false;
			scope.phoneNumberEditShow = false;
			scope.ratingEditShow = false;
			scope.termsEditShow = false;
			scope.editButtonText = "Edit";
			scope.numbers = [{number: 0}, {number: 1}, {number: 2}, {number: 3}, {number: 4}, {number: 5}];
			scope.addNewFeatureShow = false;
			scope.editFeatureShow = [];
			var featureName = [];

			scope.$watch('hotel', function(){
				scope.hotelName = scope.hotel.name;
				scope.address = scope.hotel.address;
				scope.rating = scope.numbers[scope.hotel.rating];
				scope.email = scope.hotel.email;
				scope.phoneNumber = scope.hotel.phone;
				scope.terms = scope.hotel.terms;
				scope.features = scope.hotel.features;
				scope.addNewFeatureShow = true;
				scope.editFeatureShow = [];
				featureName = [];
				for(var i = 0; i< scope.hotel.features.length; i++){
					scope.editFeatureShow.push(false);
					featureName.push("");
				}
			});

			scope.editButtonClicked = function(){
				if(scope.editButtonText == "Edit"){
					scope.editButtonText = "Save";
					scope.hotelNameEditShow = true;
					scope.addressEditShow = true;
					scope.emailEditShow = true;
					scope.phoneNumberEditShow = true;
					scope.ratingEditShow = true;
					scope.termsEditShow = true;
					scope.featureEditShow = true;
				} else {
					scope.editButtonText = "Edit";
					scope.hotelNameEditShow = false;
					scope.addressEditShow = false;
					scope.emailEditShow = false;
					scope.phoneNumberEditShow = false;
					scope.ratingEditShow = false;
					scope.termsEditShow = false;
					scope.featureEditShow = false;
					scope.hotel.name = scope.hotelName;
					scope.hotel.address = scope.address;
					scope.hotel.email = scope.email;
					scope.hotel.rating = scope.rating.number;
					scope.hotel.phone = scope.phoneNumber;
					scope.hotel.terms = scope.terms;
				}
			}

			scope.cancelButtonClicked = function(){
				scope.editButtonText = "Edit";
				scope.hotelNameEditShow = false;
				scope.addressEditShow = false;
				scope.emailEditShow = false;
				scope.phoneNumberEditShow = false;
				scope.ratingEditShow = false;
				scope.termsEditShow = false;
				scope.featureEditShow = false;
			}

			scope.addFeature = function() {
				if(!scope.features){
					scope.features = [];
				}
				console.log(scope.new_feature);
				if(scope.new_feature == "" || !scope.new_feature){
				}else{
					scope.features.push({ name: scope.new_feature });
					scope.new_feature = "";
				}
            };

			scope.removeFeature = function (idx) {
                scope.features.splice( idx, 1 );
            };

			scope.editFeature = function(feature, index){
				if(!scope.editFeatureShow[index]){
					scope.editFeatureShow[index] = true;
					featureName[index] = feature.name;
				} else {
					scope.editFeatureShow[index] = false;
					console.log(feature.name != "");
					if(feature.name != ""){
						console.log("berisi")
					} else {
						feature.name = featureName[index];
					}
				}
			}

			scope.deleteFeature = function(feature){
				var id = scope.hotel.features.indexOf(feature);
				console.log(id);
				// var _url = "https://hotelbooking2.firebaseio.com/Hotels";
				// var itemRef = new Firebase(_url + '/Midtown/features/' + id);
				// itemRef.remove();
				scope.hotel.features.splice(id, 1);
			}
		}
	}
  }])
  .directive('bookingInformation', ['$location', '$cookieStore', '$timeout', 'Hotel', '$filter', function($location, $cookieStore, $timeout, Hotel, $filter){
	return {
		restrict: 'A',
		scope:{
			hotel: '='
		},
		link: function(scope, elm, attrs){
			scope.editShow = false;
			scope.bookingData = [];
			scope.reverse = false;
			scope.filteredItems = [];
			scope.groupedItems = [];
			scope.itemsPerPage = 7;
			scope.pagedItems = [];
			scope.currentPage = 0;
			scope.statuses = [{name: 'Not payed'}, {name: 'Payed'}, {name: 'In the room'}, {name: 'Out'}, {name: 'Invalid'}, {name: 'Deleted'}];
			scope.status = scope.statuses[0];

			scope.$watch('hotel', function(){
				var total = 0;
				$.each(scope.hotel.bookingData, function(index, roomItem) {
					total++;
				});
				scope.totalItems = total;
				scope.search();
			});

			scope.dateToYMD = function (date, format) {
				var weekday = new Array(7);
				weekday[0] = "Sunday";
				weekday[1] = "Monday";
				weekday[2] = "Tuesday";
				weekday[3] = "Wednesday";
				weekday[4] = "Thursday";
				weekday[5] = "Friday";
				weekday[6] = "Saturday";

				var monthName = new Array(12);
				monthName[0] = "January";
				monthName[1] = "February";
				monthName[2] = "March";
				monthName[3] = "April";
				monthName[4] = "May";
				monthName[5] = "June";
				monthName[6] = "July";
				monthName[7] = "August";
				monthName[8] = "September";
				monthName[9] = "October";
				monthName[10] = "November";
				monthName[11] = "December";

				var d = date.getDate();
				var m = date.getMonth() + 1;
				var y = date.getFullYear();
				var day = date.getDay();
				if (format == "String")
					return '' + y + '-' + (m<=9 ? '0' + m : m) + '-' + (d <= 9 ? '0' + d : d);
				else if (format == "Object")
					return {
						date: (d <= 9 ? '0' + d : d),
						month: (monthName[m-1]),
						year: y,
						day: (weekday[day]),
						weekday: (day == 0 || day == 6 ? true : false) }
			}

			scope.groupToPages = function () {
				scope.pagedItems = [];
				var i = 0;
				$.each(scope.filteredItems, function(index, roomItem) {
					if (i % scope.itemsPerPage === 0) {
						scope.pagedItems[Math.floor(i / scope.itemsPerPage)] = [scope.filteredItems[i]];
					} else {
						scope.pagedItems[Math.floor(i / scope.itemsPerPage)].push(scope.filteredItems[i]);
					}
					i++;
				});
				//console.log(scope.pagedItems);
			};

			var searchMatch = function (haystack, needle) {
				if (!needle) {
					return true;
				}
				var bools = false;
				console.log(haystack.toString());
				if(typeof haystack != 'number' && typeof needle != 'number'){
					return haystack.toLowerCase().indexOf(needle.toLowerCase()) !== -1;
				} else {
					return haystack.toString().toLowerCase().indexOf(needle) !== -1;
				}
			};

			scope.search = function () {
				scope.firstName = null;
				var filter = [];
				scope.items = [];
				scope.filteredItems = []
				$.each(scope.hotel.bookingData, function(index, item){
					scope.items.push(item);
				});

				$.each(scope.items, function(index, item){
					var length = scope.filteredItems.length;
					for(var attr in item) {
						if(typeof item[attr] != 'object'){
							if (searchMatch(item[attr], scope.query) && (length + 1) != scope.filteredItems.length)
								scope.filteredItems.push(item);
						}
					}
				});

				scope.id = null;

				var i = scope.totalItems;
				for(var i = scope.totalItems; i> 0; i--){
					$.each(scope.filteredItems, function(index, item){
						if(i == item.id && item.status != "Deleted"){
							filter.push(item);
						}
					});
				}
				for(var i = scope.totalItems; i> 0; i--){
					$.each(scope.filteredItems, function(index, item){
						if(i == item.id && item.status == "Deleted"){
							filter.push(item);
						}
					});
				}

				console.log(filter);
				//console.log(filter);
				// $.each(scope.filteredItems, function(index, item){
					// if(i == item.id){
						// filter.push(item);
					// }
				// });
				scope.filteredItems = filter;
				//console.log(scope.filteredItems);

				scope.currentPage = 0;
				// now group by pages
				scope.groupToPages();
			};

			scope.range = function (start, end) {
				var ret = [];
				if (!end) {
					end = start;
					start = 0;
				}
				for (var i = start; i < end; i++) {
					ret.push(i);
				}
				return ret;
			};

			scope.prevPage = function () {
				if (scope.currentPage > 0) {
					scope.currentPage--;
				}
			};

			scope.nextPage = function () {
				if (scope.currentPage < scope.pagedItems.length - 1) {
					scope.currentPage++;
				}
			};

			scope.setPage = function () {
				scope.currentPage = this.n;
			};

			scope.sort_by = function(newSortingOrder) {
				if (scope.sortingOrder == newSortingOrder)
					scope.reverse = !scope.reverse;

				scope.sortingOrder = newSortingOrder;

				// icon setup
				$('th i').each(function(){
					// icon reset
					$(this).removeClass().addClass('icon-sort');
				});
			};

			scope.viewBooking = function(bookingData) {
				scope.bookingData = bookingData;
				scope.editShow = false;

				var status = {name: bookingData.status};
				//console.log(status.name + " " + scope.statuses.indexOf(status))
				for(var i = 0; i< scope.statuses.length; i++){
					if(scope.statuses[i].name == status.name){
						scope.status = scope.statuses[i];
					}
				}

				scope.roomNumber = bookingData.roomNumber;
				$.each(scope.pagedItems[scope.currentPage], function(index, item){
					if(bookingData.id == item.id)
					{
						scope.id = bookingData.id;
					}
				})
				scope.firstName = bookingData.firstName;
				scope.lastName = bookingData.lastName;
				scope.email = bookingData.email;
				scope.contactNumber = bookingData.contactNumber;
				if(!bookingData.organization){
					scope.organization = bookingData.organization;
				}
				scope.addressLine1 = bookingData.addressLine1;
				scope.city = bookingData.city;
				if(!bookingData.addressLine2){
					scope.addressLine2 = bookingData.addressLine2;
				}
				scope.arrivalTime = bookingData.arrivalTime;
				scope.postCode = bookingData.postCode;
				if(!bookingData.loyaltyID){
					scope.loyaltyID = bookingData.loyaltyID;
				}
				if(!bookingData.comment){
					scope.comment = bookingData.comment;
				}

				if(!bookingData.hear){
					scope.hear = bookingData.hear;
				}
				scope.cardType = bookingData.cardType;
				scope.cardNumber = bookingData.cardNumber;
				scope.cardCCV = bookingData.cardCCV;
				scope.cardUser = bookingData.cardUser;
			}

			scope.editBooking = function(bookData){
				$timeout(function(){
					scope.viewBooking(bookData);
					scope.editShow = true;
				})
			}

			scope.saveBooking = function() {
				var id = 0;
				$.each(scope.hotel.bookingData, function(index, item){
					if(item.id == scope.bookingData.id){
						item.status = scope.status.name;
					}
				})
				scope.editShow = false;
				scope.firstName = null;
			}

			Array.prototype.indexOfRoomId = function(id) {
				for (var i = 0; i < this.length; i++)
					if (this[i].roomId === id)
						return i;
				return -1;
			}

			scope.invalidBooking = function(bookingData){
				$timeout(function(){
					scope.firstName = null;
				})

				var url = "https://hotelbooking2.firebaseio.com/Hotels";
				$.each(scope.hotel.bookingData, function(index, item){
					if(item.id == bookingData.id){
						item.status = "Deleted";
					}
				});

				scope.search();
				for(var i = 0; i < bookingData.roomNumber.length; i++){
					var id = scope.hotel.roomData.indexOfRoomId(bookingData.roomNumber[i].number);

					var startDateBooking = new Date(bookingData.startDate);
					var endDateBooking = new Date(bookingData.endDate);
					var startDateBookObj = scope.dateToYMD(startDateBooking, 'Object');
					//console.log(startDateBookObj);
					while(startDateBooking.getDate() != endDateBooking.getDate()){
						var startDateBookObj = scope.dateToYMD(startDateBooking, 'Object');
						var j = 0;
						$.each(scope.hotel.roomData[id].occuDate, function(index, item) {
							var dateRoomData = new Date(item.date);
							var dateRoomDataObj = scope.dateToYMD(dateRoomData, 'Object');
							if(dateRoomDataObj.date == startDateBookObj.date && dateRoomDataObj.month == startDateBookObj.month && dateRoomDataObj.year == startDateBookObj.year){
								var itemRef = new Firebase(url + "/Midtown/roomData/"+ id + "/occuDate/" + index);
								itemRef.remove();
							}
							j++;
						})
						startDateBooking.setDate(startDateBooking.getDate() + 1);
					}
				}

			}

		}
	}
  }])
  .directive('roomtypeInformation', ['uploadService', '$location', '$cookieStore', '$timeout', 'Hotel', '$filter', function(uploadService, $location, $cookieStore, $timeout, Hotel, $filter){
	return{
		restrict: 'A',
		scope:{
			hotel: '='
		},
		link: function(scope, alm, attr){
			var notifModal = $('#successModal');
			scope.files = [];
			scope.roomTypeData = [];
			scope.reverse = false;
			scope.filteredTypes = [];
			scope.groupedTypes = [];
			scope.itemsPerPage = 7;
			scope.pagedtypes = [];
			scope.currentPage = 0;
			scope.editShow = false;
			scope.$watch('hotel', function(){
				var total = 0;
				$.each(scope.hotel.rooms, function(index, roomItem) {
					total++;
				});
				scope.totalItems = total;
				console.log(scope.totalItems);
				scope.search();
			});

			scope.prevPage = function () {
				if (scope.currentPage > 0) {
					scope.currentPage--;
				}
			};

			scope.nextPage = function () {
				if (scope.currentPage < scope.pagedTypes.length - 1) {
					scope.currentPage++;
				}
			};

			scope.setPage = function () {
				scope.currentPage = this.n;
			};

			Array.prototype.indexOfRoomNumber = function(id) {
				for (var i = 0; i < this.length; i++)
					if (this[i].number === id)
						return i;
				return -1;
			}

			Array.prototype.indexOfRoomType = function(name) {
				for (var i = 0; i < this.length; i++)
					if (this[i].roomType === name)
						return i;
				return -1;
			}

			scope.groupToPages = function () {
				scope.pagedTypes = [];
				var i = 0;
				$.each(scope.filteredTypes, function(index, roomItem) {
					if (i % scope.itemsPerPage === 0) {
						scope.pagedTypes[Math.floor(i / scope.itemsPerPage)] = [scope.filteredTypes[i]];
					} else {
						scope.pagedTypes[Math.floor(i / scope.itemsPerPage)].push(scope.filteredTypes[i]);
					}
					i++;
				});
				console.log(scope.pagedItems);
			};

			var searchMatch = function (haystack, needle) {
				if (!needle) {
					return true;
				}
				var bools = false;
				console.log(haystack.toString());
				if(typeof haystack != 'number' && typeof needle != 'number'){
					return haystack.toLowerCase().indexOf(needle.toLowerCase()) !== -1;
				} else {
					return haystack.toString().toLowerCase().indexOf(needle) !== -1;
				}
			};

			scope.search = function () {
				scope.name = null;
				scope.id = null;
				var filter = [];
				scope.items = [];
				scope.filteredTypes = []
				$.each(scope.hotel.rooms, function(index, item){
					scope.items.push(item);
				});

				$.each(scope.items, function(index, item){
					var length = scope.filteredTypes.length;
					for(var attr in item) {
						if(typeof item[attr] != 'object'){
							if (searchMatch(item[attr], scope.query) && (length + 1) != scope.filteredTypes.length)
								scope.filteredTypes.push(item);
						}
					}
				});

				console.log(scope.filteredTypes)

				scope.currentPage = 0;
				// now group by pages
				scope.groupToPages();
			};

			scope.viewRoomType = function(data) {
				scope.roomTypeData = data;
				scope.editShow = false;
				scope.newShow = false;
				scope.photos = [];
				$.each(scope.pagedTypes[scope.currentPage], function(index, item){
					if(data.id == item.id){
						scope.id = data.id;
					}
				})
				var features = data.features;
				scope.features = features;
				scope.name = data.name;
				scope.desc = data.desc;
				scope.fullRate = data.fullRate;
				scope.photos = data.images;
				// for(var i = 0; i< data.images.length; i++){
					// scope.photos.push(data.images[0]);
				// }
				$('#fileupload2')
				.fileupload({
					acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
					url:"/server/UploadHandler.php?folder="+data.name.toLowerCase(),
					sequentialUploads: true,
					autoUpload: true,
					singleFileUploads: false,
				}).bind('fileuploadadd', function(e, data){
					// Add the files to the list
					var numFiles = scope.fileList2.length;
					var id = scope.hotel.rooms.indexOf(scope.roomTypeData);

					for (var i=0; i < data.files.length; ++i) {
						var file = data.files[i];

					// .$apply to update angular when something else makes changes
						scope.$apply(
							scope.fileList2.push({name: file.name})
						);
					}
					data.submit();
				}).bind('fileuploadprogress', function (e, data) {
					var progress = parseInt(data.loaded / data.total * 100, 10);
					$('#progress2 .bar').css(
						'width',
						progress + '%'
					);
					$('#progress2 .bar').css(
						'background-color',
						'#5cb85c'
					);
					$('#progress2 .bar').css(
						'height',
						'18px'
					);
					scope.progress= progress;
				}).bind('fileuploaddone', function(e, data){
					$('#progress2 .bar').css(
						'width',
						'0%'
					);
					scope.imageRefresh();
				});

			}

			scope.imageRefresh = function(){
				var id = scope.hotel.rooms.indexOf(scope.roomTypeData);

				for (var i=0; i < scope.fileList2.length; ++i){
					var jml = 0
					for(var j = 0; j < scope.hotel.rooms[id].images.length; j++){
						if(scope.hotel.rooms[id].images[j].name == scope.fileList2[i].name){
							jml++;
						}
					}
					if(jml == 0){
						scope.$apply(
							scope.hotel.rooms[id].images.push({
								uri: 'img/demo-hotel/'+ scope.roomTypeData.name.toLowerCase() + '/' + scope.fileList2[i].name,
								name: scope.fileList2[i].name,
								folder: scope.roomTypeData.name.toLowerCase()
							})
						);
					}
				}

			}
			scope.addNewRoomType = function(){
				scope.newRoomTypeForm.$setPristine();
				$('#progress .bar').css(
					'width',
					'0%'
				);
				console.log('yeah');
				scope.name = null;
				scope.newShow = true;
				scope.tags = [];
				scope.newName = null;
				scope.newDesc = null;
				scope.newFullRate = null;
				scope.newNumber = null;
				scope.isError();
			}

			scope.SubmitNewRoom = function() {
				//console.log(scope.newName);
				if(!scope.newName){
					scope.newName = '';
				}
				console.log(scope.newName);
				$("#fileupload").fileupload({
					acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
					url: "/server/UploadHandler.php?folder="+scope.newName.toLowerCase(),
					sequentialUploads: true
				}).bind('fileuploaddone', function(data){
					notifModal.modal('show');
					scope.search();
				});
				scope.data.submit();
				scope.uris = [];
				for(var i = 0; i< scope.fileList.length; i++){
					scope.uris.push({uri:'img/demo-hotel/' + scope.newName.toLowerCase() + '/' + scope.fileList[i].name, name:scope.fileList[i].name, folder:scope.newName.toLowerCase()});
				}

				if(!scope.hotel.rooms){
					scope.hotel.rooms = [];
				}
				scope.hotel.rooms.push({id: scope.newName.toLowerCase(), name: scope.newName, desc: scope.newDesc, fullRate: scope.newFullRate, features: scope.tags, images: scope.uris});
				var length = 0;

				if(scope.hotel.roomData){
					length = scope.hotel.roomData.length;
				} else {
					scope.hotel.roomData = [];
				}
				scope.successText = "Add new room type successful!";

				for(var i = 0; i< scope.newNumber; i++){
					scope.hotel.roomData.push({roomId: scope.hotel.roomData[length - 1].roomId + i + 1, roomType: scope.newName});
				}

			}

			scope.removeFoto = function(image){
				console.log(image.uri);
				$.ajax({
					  type:"POST",
					  url:"/server/delete.php?folder="+image.folder,
					  data:{ name: image.name},
					  success: function(html){
							var id = scope.hotel.rooms.indexOf(scope.roomTypeData);
							var idFoto = scope.hotel.rooms[id].images.indexOf(image);
							console.log(idFoto);
							if(idFoto >= 0){
								scope.$apply(
									scope.hotel.rooms[id].images.splice(idFoto, 1)
								);
							}
					  },
					  error: function(msg){
						console.log("no");
					  }
					});
			}

			scope.removeFolder = function(folder){
				$.ajax({
				  type:"POST",
				  url:"/server/deleteFolder.php",
				  data:{ folder: folder},
				  success: function(html){
					console.log("yeah");
				  },
				  error: function(msg){
					console.log("no");
				  }
				});
			}

			notifModal.on('hidden.bs.modal', function () {
				scope.newShow = false;
				scope.$apply();
			});

			scope.closeNotifBooking = function() {
				$timeout(function(){
					console.log(notifModal);
					notifModal.modal('hide');
				})
			};

			scope.deleteRoomType = function(roomType){
				var id = scope.hotel.rooms.indexOf(roomType);
				var url = "https://hotelbooking2.firebaseio.com/Hotels";
				var jumlah = 0;
				$.each(scope.hotel.roomData, function(index, item){
					if(item.roomType == roomType.name){
						$.each(scope.hotel.bookingData, function(index, bookData){
							var idKamar = bookData.roomNumber.indexOfRoomNumber(item.roomId);
							if(idKamar >= 0){
								bookData.status = "Deleted";
							}
						});
						jumlah++;
					}
				})

				for(var i = 0; i< jumlah; i++){
					var roomId = scope.hotel.roomData.indexOfRoomType(roomType.name);
					scope.hotel.roomData.splice(roomId, 1);
				}

				scope.hotel.rooms.splice(id,1);
				scope.removeFolder(roomType.name.toLowerCase());

				scope.search();
				scope.formShow = false;
				scope.successText = "Delete room type successful!";
				notifModal.modal('show');
			}

			scope.editRoomType = function(roomType){
				$timeout(function(){
					scope.viewRoomType(roomType);
					scope.editShow = true;
				})
			}

			scope.cancelButtonClicked = function(){
				scope.editShow = false;
			}

			scope.saveRoomType = function(){
				var id = scope.hotel.rooms.indexOf(scope.roomTypeData);
				$.each(scope.hotel.roomData, function(index, item){
					if(item.roomType == scope.hotel.rooms[id].name){
						item.roomType = scope.name;
					}
				})
				scope.hotel.rooms[id].name = scope.name;
				scope.hotel.rooms[id].desc = scope.desc;
				scope.hotel.rooms[id].fullRate = scope.fullRate;
				//scope.hotel.rooms[id].features = scope.features;
				scope.editShow = false;
			}

			scope.isError = function(){
				if(angular.isUndefined(scope.newRoomTypeForm.newName) || angular.isUndefined(scope.newRoomTypeForm.newDesc) || angular.isUndefined(scope.newRoomTypeForm.newFullRate) || angular.isUndefined(scope.newRoomTypeForm.newNumber) || scope.tags.length == 0 || scope.fileList.length == 0) {
					scope.error = true;
				} else {
					$timeout(function() {
						if(scope.newRoomTypeForm.newName.$valid && scope.newRoomTypeForm.newDesc.$valid && scope.newRoomTypeForm.newFullRate.$valid && scope.newRoomTypeForm.newNumber.$valid){
							console.log('gak error');
							scope.error = false;
						}
						else{
							scope.error = true;
						}
					});
				}
			}

			scope.formChange = function(){
				scope.isError();
			}

			//FOR TAG FEATURE
			scope.add = function() {
				console.log(scope.tags);
				if(!scope.tags){
					scope.tags = [];
				}
				console.log(scope.new_value);
				if(scope.new_value == "" || !scope.new_value){
				}else{
					scope.tags.push({ name: scope.new_value });
					scope.new_value = "";
					scope.isError();
				}
            };

			//FOR TAG FEATURE
			scope.addFeature = function() {
				if(!scope.features){
					scope.features = [];
				}
				console.log(scope.new_feature);
				if(scope.new_feature == "" || !scope.new_feature){
				}else{
					scope.features.push({ name: scope.new_feature });
					scope.new_feature = "";
				}
				console
            };

            //This is the ng-click handler to remove an item
            scope.remove = function (idx) {
                scope.tags.splice( idx, 1 );
				scope.isError();
            };

			scope.removeFeature = function (idx) {
                scope.features.splice( idx, 1 );
            };

            // Capture all keypresses
            $('#tagsinput').bind('keypress', function (event) {
                // But we only care when Enter was pressed
                if ( event.keyCode == 13 ) {
                    // There's probably a better way to handle this...
                    scope.$apply(scope.add );
                }
            });

			scope.options = {
				maxFileSize: 5000000,
				acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i
			};

			scope.fileList = [];
			scope.fileList2 = [];

			$('#fileupload')
				.fileupload({
					acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
					sequentialUploads: true,
					autoUpload: false,
					singleFileUploads: false,
				})
				.bind('fileuploadadd', function(e, data){
					// Add the files to the list
					var numFiles = scope.fileList.length;

					for (var i=0; i < data.files.length; ++i) {
						var file = data.files[i];

					// .$apply to update angular when something else makes changes
						scope.$apply(
							scope.fileList.push({name: file.name})
						);
					}
					scope.data = data;
					scope.isError();
				})
				.bind('fileuploadprogress', function (e, data) {
					var progress = parseInt(data.loaded / data.total * 100, 10);
					$('#progress .bar').css(
						'width',
						progress + '%'
					);
					$('#progress .bar').css(
						'background-color',
						'#5cb85c'
					);
					$('#progress .bar').css(
						'height',
						'18px'
					);
					scope.progress= progress;
				})
				.bind('fileuploaddone', function (e,data) {
					scope.fileList = [];
					jQuery("#fileupload").find(".files").empty();
				});

		}
	}
  }])
  .directive('ngReallyClick', [function() {
    return {
        restrict: 'A',
        link: function(scope, element, attrs) {
            element.bind('click', function() {
                var message = attrs.ngReallyMessage;
                if (message && confirm(message)) {
                    scope.$apply(attrs.ngReallyClick);
                }
            });
        }
    }
  }])
  .directive('roomInformation', ['$location', '$cookieStore', '$timeout', 'Hotel', '$filter', function($location, $cookieStore, $timeout, Hotel, $filter){
	return {
		restrict: 'A',
		scope: {
			hotel: '='
		},
		link: function(scope, elm, attr){
			scope.formShow = false;
			scope.roomData = [];
			scope.reverse = false;
			scope.filteredTypes = [];
			scope.groupedTypes = [];
			scope.itemsPerPage = 7;
			scope.pagedtypes = [];
			scope.currentPage = 0;
			var notifModal = $('#successModal');
			scope.editRoom = function(room){
				$timeout(function(){
					scope.viewRoom(room);
					scope.editShow = true;
				})

			}

			scope.viewRoom = function(data) {
				scope.roomData = data;
				scope.formShow = true;
				scope.editShow = false;
				scope.newShow = false;
				scope.photos = [];
				$.each(scope.pagedTypes[scope.currentPage], function(index, item){
					if(data.roomId == item.roomId){
						scope.id = data.roomId;
					}
				})
				scope.occuDate = [];
				scope.occuDate = data.occuDate;
				scope.roomTypes = scope.hotel.rooms;
				scope.roomId = data.roomId;

				for(var i = 0; i< scope.roomTypes.length; i++){
					if(scope.roomTypes[i].name == data.roomType){
						scope.roomType = scope.roomTypes[i];
					}
				}
			}

			scope.$watch('hotel', function(){
				var total = 0;
				$.each(scope.hotel.roomData, function(index, roomItem) {
					total++;
				});
				scope.totalItems = total;
				scope.search();
			});

			scope.range = function (start, end) {
				var ret = [];
				if (!end) {
					end = start;
					start = 0;
				}
				for (var i = start; i < end; i++) {
					ret.push(i);
				}
				return ret;
			};

			scope.groupToPages = function () {
				scope.pagedTypes = [];
				var i = 0;
				$.each(scope.filteredTypes, function(index, roomItem) {
					if (i % scope.itemsPerPage === 0) {
						scope.pagedTypes[Math.floor(i / scope.itemsPerPage)] = [scope.filteredTypes[i]];
					} else {
						scope.pagedTypes[Math.floor(i / scope.itemsPerPage)].push(scope.filteredTypes[i]);
					}
					i++;
				});
				console.log(scope.pagedItems);
			};

			scope.cancelButtonClicked = function(){
				scope.editShow = false;
			}

			scope.saveRoom = function(){
				var id = scope.hotel.roomData.indexOf(scope.roomData);
				scope.hotel.roomData[id].roomId = scope.roomId;
				scope.hotel.roomData[id].roomType = scope.roomType.name;
				scope.editShow = false;
			}

			Array.prototype.indexOfRoomNumber = function(id) {
				for (var i = 0; i < this.length; i++)
					if (this[i].number === id)
						return i;
				return -1;
			}

			Array.prototype.indexOfRoomId = function(id) {
				for (var i = 0; i < this.length; i++)
					if (this[i].roomId === id)
						return i;
				return -1;
			}

			scope.deleteRoom = function(roomData){
				var id = scope.hotel.roomData.indexOf(roomData);
				$.each(scope.hotel.bookingData, function(index, bookData){
					var idKamar = bookData.roomNumber.indexOfRoomNumber(roomData.roomId);
					if(idKamar >= 0){
						bookData.status = "Deleted";
					}
				});

				scope.hotel.roomData.splice(id, 1);
				scope.search();
				scope.formShow = false;
				scope.successText = "Delete room successful!"
				notifModal.modal('show');
			}

			scope.addNewRoom = function() {
				scope.newRoomForm.$setPristine();
				scope.formShow = false;
				scope.newShow = true;
				scope.newRoomId = null;
				scope.roomTypes = scope.hotel.rooms;
				scope.isError();
				scope.datas = [];
			}

			scope.SubmitNewRoom = function() {
				var id = scope.hotel.roomData.indexOfRoomId(parseInt(scope.newRoomId));
				console.log(id);
				if(id >= 0){
					scope.successText = "Already have room with this number";
					notifModal.modal('show');
				} else {
					if(!scope.hotel.roomData){
						scope.hotel.roomData = [];
					}
					scope.hotel.roomData.push({roomId: parseInt(scope.newRoomId), roomType: scope.newRoomType.name});
					scope.newShow = false;
					scope.successText = "Add new room type successful!";
					notifModal.modal('show');
					scope.search();
				}
			}

			scope.formChange = function(){
				scope.isError();
			}

			scope.isError = function(){
				if(angular.isUndefined(scope.newRoomForm.newRoomId) || angular.isUndefined(scope.newRoomForm.newRoomType)) {
					scope.error = true;
				} else {
					$timeout(function() {
						if(scope.newRoomForm.newRoomId.$valid && scope.newRoomForm.newRoomType.$valid){
							console.log('gak error');
							scope.error = false;
						}
						else{
							scope.error = true;
						}
					});
				}
			}

			var searchMatch = function (haystack, needle) {
				if (!needle) {
					return true;
				}
				var bools = false;
				console.log(haystack.toString());
				if(typeof haystack != 'number' && typeof needle != 'number'){
					return haystack.toLowerCase().indexOf(needle.toLowerCase()) !== -1;
				} else {
					return haystack.toString().toLowerCase().indexOf(needle) !== -1;
				}
			};

			scope.prevPage = function () {
				if (scope.currentPage > 0) {
					scope.currentPage--;
				}
			};

			scope.nextPage = function () {
				if (scope.currentPage < scope.pagedTypes.length - 1) {
					scope.currentPage++;
				}
			};

			scope.setPage = function () {
				scope.currentPage = this.n;
			};

			scope.search = function () {
				scope.name = null;
				scope.id = null;
				var filter = [];
				scope.items = [];
				scope.filteredTypes = []
				$.each(scope.hotel.roomData, function(index, item){
					scope.items.push(item);
				});

				$.each(scope.items, function(index, item){
					var length = scope.filteredTypes.length;
					for(var attr in item) {
						if(typeof item[attr] != 'object'){
							if (searchMatch(item[attr], scope.query) && (length + 1) != scope.filteredTypes.length)
								scope.filteredTypes.push(item);
						}
					}
				});

				scope.currentPage = 0;
				// now group by pages
				scope.groupToPages();
			};
		}
	}
  }])
  .directive('newsletterInformation', ['$location', '$cookieStore', '$timeout', 'Hotel', '$filter', function($location, $cookieStore, $timeout, Hotel, $filter){
	return {
		restrict: 'A',
		scope: {
			hotel: '='
		},
		link: function(scope, elm, attr){
			var _url = "https://hotelbooking2.firebaseio.com/Hotels";
			scope.reverse = false;
			scope.filteredTypes = [];
			scope.groupedTypes = [];
			scope.itemsPerPage = 7;
			scope.pagedtypes = [];
			scope.currentPage = 0;
			var notifModal = $('#successModal');

			scope.$watch('hotel', function(){
				var total = 0;
				$.each(scope.hotel.newsletterData, function(index, item) {
					total++;
				});
				scope.totalItems = total;
				scope.search();
			});

			scope.range = function (start, end) {
				var ret = [];
				if (!end) {
					end = start;
					start = 0;
				}
				for (var i = start; i < end; i++) {
					ret.push(i);
				}
				return ret;
			};

			scope.groupToPages = function () {
				scope.pagedTypes = [];
				var i = 0;
				$.each(scope.filteredTypes, function(index, roomItem) {
					if (i % scope.itemsPerPage === 0) {
						scope.pagedTypes[Math.floor(i / scope.itemsPerPage)] = [scope.filteredTypes[i]];
					} else {
						scope.pagedTypes[Math.floor(i / scope.itemsPerPage)].push(scope.filteredTypes[i]);
					}
					i++;
				});
				console.log(scope.pagedItems);
			};

			var searchMatch = function (haystack, needle) {
				if (!needle) {
					return true;
				}
				var bools = false;
				console.log(haystack.toString());
				if(typeof haystack != 'number' && typeof needle != 'number'){
					return haystack.toLowerCase().indexOf(needle.toLowerCase()) !== -1;
				} else {
					return haystack.toString().toLowerCase().indexOf(needle) !== -1;
				}
			};

			scope.prevPage = function () {
				if (scope.currentPage > 0) {
					scope.currentPage--;
				}
			};

			scope.nextPage = function () {
				if (scope.currentPage < scope.pagedTypes.length - 1) {
					scope.currentPage++;
				}
			};

			scope.setPage = function () {
				scope.currentPage = this.n;
			};

			scope.search = function () {
				scope.name = null;
				scope.id = null;
				var filter = [];
				scope.items = [];
				scope.filteredTypes = []
				$.each(scope.hotel.newsletterData, function(index, item){
					scope.items.push(item);
				});

				$.each(scope.items, function(index, item){
					var length = scope.filteredTypes.length;
					for(var attr in item) {
						if(typeof item[attr] != 'object'){
							if (searchMatch(item[attr], scope.query) && (length + 1) != scope.filteredTypes.length)
								scope.filteredTypes.push(item);
						}
					}
				});

				scope.currentPage = 0;
				// now group by pages
				scope.groupToPages();
			};

			scope.deleteNews = function(newsletter){
				var id;
				$.each(scope.hotel.newsletterData, function(index,item){
					if(item.email == newsletter.email){
						console.log(item.email + " " + index);
						id = index;
					}
				})
				var itemRef = new Firebase(_url + '/Midtown/newsletterData/' + id);
				console.log(itemRef);
				itemRef.remove();
				scope.search();
				scope.successText = "Delete newsletter successful!"
				notifModal.modal('show');
			}
		}
	}
}]);


Well, I haven't seen this kind of hype in three years. Three years ago, Google announced it was launching a new social network: G+. The internets went crazy, partly because they didn't make it open to everyone. In order to get into G+, you needed an invitation. And like that restaurant that always has a line, you figure, well, it must be good, right? If people are willing to line up for it?
It's working. Ello has gone immediately viral. At last count, 31,000 people per hour were joining. Clearly it's a concept whose time has come, and the timing couldn't be better.
Love how clean and simple the design is.
It works similarly to twitter, in that you can have conversations with people by @mentioning them. I like that this feature is already built in, and it works quite well, as it's a format we're already familiar with.
I love the idea of an anti-facebook with no ads.
The population, at this point, appears to be primarily artists, creatives, and tech peeps. There are lots of beautiful images to look at, and everyone's profile and updates are funky and quirky (which I really like, being a little quirky myself).
It's still very, very beta. I mean, green beta. So, there are things that it simply cannot do yet that are things I can't live without. For example, there's not yet an app version, which means no notifications on my phone, which is where I spend a great deal of my time. There is, in fact, no notification system whatsoever, so every time someone new follows me, or mentions me in a comment, I get an email. I really hate that system–I have all email notifications turned off on all my social networks. I get too much email as it is. Ello has a list of its features and future features here.
What is it?? Other than "the anti-facebook," no one seems to really know. I can live with this, though. In the olden days of Twitter, for example, we didn't really know what we were doing, either, but it grew into this really cool thing. I see Ello having the possibility to do that, as well, but right now, things are a little… foggy.
Many members of the LGBTQ community are embracing Ello because it doesn't require you to give your real name when you join. Understandably, members of the LGBTQ community are concerned that they may expose themselves to hatemongering (or worse) if the world knew their real names. However, NotYourExRotic debunks that here.
How are they going to make money? I think it's very idealistic (and admirable) to want to create a social network that (supposedly) protects your private information, and won't have ads. But at the end of the day, Ello is a business, and at some point, they need to start making money. How are they going to do that? Aral Balkan wrote a great piece about Ello's monetization called Ello, Goodbye.
Ello says, "Very soon we will begin offering special features to our users. If we create a special feature that you like, you can choose to pay a very small amount of money to add it to your Ello account forever." So, essentially, they are talking about a freemium product. It could work. Hootsuite is a freemium product that has been incredibly successful–but it is also incredibly useful, and I don't see Ello being that yet.
As with any other new social network, I tend to take a "wait and see" attitude. After all, the network that launched three years ago to great acclaim is now, according to many reports, on the rocks. And while I, personally, would appreciate an anti-Facebook, Ello will have to be more than just that one-trick pony to tip into the mainstream.
In the mean time, if you want to check Ello out for yourself, email me for an invite.
UPDATE: Ello gave me 25 invites, and they are now all gone.


jzhangow has not yet been in a debate.
Post a comment to jzhangow's profile.
jzhangow does not have any Debate.org friends.
jzhangow has not added any photo albums.
If you are logged in, you will also see green or red bullets next to each issue, which indicate whether you agree or disagree with jzhangow on that particular issue.
You can also click each issue to find other members that agree with jzhangow's position on the issue.


text:
'You' Season 4 Trailer: Penn Badgley's Joe Is Dangerous As Ever In Netflix Series
By Emerson Pearson.
The predator becomes the prey in the season four trailer for "You."
Joe Goldberg, played by Penn Badgley, returns as Professor Jonathan Moore in the season 4 trailer for "You," which aptly features the song "I Ran (So Far Away)" by Hidden Citizens.
The beginning of the teaser sees Joe attempting to reconnect with Marienne, played by Tati Gabrielle. She quickly shoots down his efforts. "You're a murderer, Joe," she tells him. "You're wrong about me. I'm gonna prove it to you," he insists.
'Inside Job': Fans React With Shock, Anger When Netflix Cancels Show After Previously Announcing Renewal
Joe then travels to London, where he begins embracing his new identity as a professor and laying low, finding himself in the realm of upper-echelon society, whom he refers to as "the most insane, damaged people on Earth: a circle of privileged douchebags."
'You' season 4. (L to R) Ozioma Whenu as Blessing, Ben Wiggins as Roald, Dario Coates as Connie, Lukas Gage as Adam, Tilly Keeper as Lady Phoebe, Charlotte Ritchie as Kate and Niccy Lin as Sophie Soo
— Netflix Studios
Though he tries to escape his past, Joe's new lifestyle quickly reverts to his old ways.
"I do miss having someone out there," Joe narrates as he observes an unsuspecting woman from his apartment window. "Hello," he continues before trying to stop himself. "No. No. I am not interested. Nope. Not interested. I don't want to know. Why does the universe keep doing this to me?"
'You' season 4. (L to R) Charlotte Ritchie as Kate, Penn Bedgley as Joe.
Halfway through the trailer, the roles are reversed, and Joe becomes the one with someone lurking after him as he begins to receive shady texts from an unknown number.
'Wednesday' Renewed By Netflix After Breaking Viewership Records
"Nice jacket. Brown's your colour," reads the first text. "Hello, Joe. Now do I have your attention?" asks another text.
After a few hectic shots of Joe running through a forest and stalking other potential victims, the trailer ends with Joe wishing his London getaway was going much smoother: "I just want my little European holiday back."
The fourth season of the smash Netflix show will be divided into two parts. Part one, which includes episodes one through five, debuts on the platform on Feb. 9, and part two, which runs episodes six through 10, is set to be available on Mar. 9.
Kate Middleton Turns 41: King Charles III And Camilla Send Sweet Birthday Message

redpajama_set_name: RedPajamaCommonCrawl