

        function setPeriod(value, periodHours, periodMins) {

            //value, periodHours, periodMins
            
            if (value.length == 3) {
                var hour = value.substr(0, 2);
                var min = value.substr(2, 1);
            }
            else {
                var hour = value.substr(0, 2);
                var min = value.substr(2, 2);
            }
            
            periodHours.val(hour);
            periodMins.val(min);

        }
		
		function get24HourTime (hour, ampm) {
		
			if (ampm == "pm") {
				if (parseInt(hour) < 12) {
					hour = parseInt(hour) + 12;
				}
				else
				{
					hour = hour;
				}
			}
            else
			{
                if (hour == 12)
                {
					hour = "00";
				}
                else
                {
					if (hour.length == 1) {
						hour = "0" + hour;
					}
					else
					{
						hour = hour;
					}
                }
            }
			
			return hour;
			
		}
		
		/* setCheckIn should be replaced with setCheckInTime during re-factoring) */
		function setCheckIn() {
		
			var hour;
			var min;
			var ampm;
			
			var myindex  = document.form1.start_time.selectedIndex;
			var SelValue = document.form1.start_time.options[myindex].value;
			if (SelValue.length == 4){
				hour=SelValue.substring(0,1);
				min=SelValue.substring(1,2);
				ampm=SelValue.substring(2);
			}
			if (SelValue.length == 5){
				if (SelValue.substring(0,1) == '1' && SelValue.substring(1,3) != '30' && SelValue.substring(1,3) != '15' && SelValue.substring(1,3) != '45'){
					hour=SelValue.substring(0,2);
					min=SelValue.substring(2,3);
					ampm=SelValue.substring(3);
				} else {
					hour=SelValue.substring(0,1);
					min=SelValue.substring(1,3);
					ampm=SelValue.substring(3);
				}
			}
			if (SelValue.length == 6){
				hour=SelValue.substring(0,2);
				min=SelValue.substring(2,4);
				ampm=SelValue.substring(4);
			}
			
			hour = get24HourTime (hour, ampm);
			
			document.form1.start_hr.value=hour;
			document.form1.start_min.value=min;
			document.form1.start_ampm.value=ampm;
			
			if (min.length==1) {
				min= "0"+min;
			}	
			
			
			
			if ($(".calSelectedDate")) {
				$(".calSelectedDate").removeClass("calSelectedDate");
				
			}
			$("#cd"+hour+min).addClass("calSelectedDate");
			$("#selectedTime").val(hour+min);
			//$(evt.target).addClass("calSelectedDate");
		}
		/** 
			setCheckInTime()
			This function is used to set elements like - startHrElement, startMinElement, startAmpmElement based on the value selectedValue (which is a time like - 02:00 PM)
			
			Sample:
			<input id="startHour" type="hidden" value="2" name="start_hr">
			<input id="startMin" type="hidden" value="0" name="start_min">
			<input id="startAmpm" type="hidden" value="pm" name="start_ampm">

			 $("#liveStartTime").change(function () {
				var selectedValue = $('#liveStartTime option:selected').val();

				setCheckInTime(selectedValue, $("#startHour"), $("#startMin"), $("#startAmpm"));
			});
		*/
		function setCheckInTime(selectedValue, startHrElement, startMinElement, startAmpmElement) {

			if (selectedValue.length == 4) {
				startHrElement.val(selectedValue.substring(0, 1));
				startMinElement.val(selectedValue.substring(1, 2));
				startAmpmElement.val(selectedValue.substring(2));
			}
			if (selectedValue.length == 5) {
				if (selectedValue.substring(0, 1) == '1' && selectedValue.substring(1, 3) != '30' && selectedValue.substring(1, 3) != '15' && selectedValue.substring(1, 3) != '45') {
					startHrElement.val(selectedValue.substring(0, 2));
					startMinElement.val(selectedValue.substring(2, 3));
					startAmpmElement.val(selectedValue.substring(3));
				} else {
					startHrElement.val(selectedValue.substring(0, 1));
					startMinElement.val(selectedValue.substring(1, 3));
					startAmpmElement.val(selectedValue.substring(3));
				}
			}
			if (selectedValue.length == 6) {
				startHrElement.val(selectedValue.substring(0, 2));
				startMinElement.val(selectedValue.substring(2, 4));
				startAmpmElement.val(selectedValue.substring(4));
			}
		}

		function setBookingTime(){
			var i=0;
			var d = document.form1.start_hr.value;
			var minute=document.form1.start_min.value;
			var ampm= document.form1.start_ampm.value;
			var dateSTR = d+minute+ampm;
			var localTime;
			if (minute == 0){
				localTime=d+':0'+minute+' '+ampm;
			}else{
				localTime=d+':'+minute+' '+ampm;
			}
			
			while ((document.form1.start_time.options[i].value != 	dateSTR.toLowerCase()) && (i < document.form1.start_time.options.length))
			{i++;}
			if (i < document.form1.start_time.options.length)
			{document.form1.start_time.selectedIndex = i;}
			document.form1.locTime.value = localTime;
		}
		function setTimeZone(){
			var myindex  = document.form1.countrytimezone.selectedIndex;
			var SelValue = document.form1.countrytimezone.options[myindex].value;
			var locTZ = document.form1.locTZ.value;
			var locTZPM = locTZ.substring(0,1);
			var locTZHr = parseFloat(locTZ.substring(1,3));
			var locTZMin = parseFloat(locTZ.substring(3,5));
			var locTotal = parseFloat(locTZ.substring(1,5));
			var h = parseFloat(document.form1.start_hr.value);
			var minute=parseFloat(document.form1.start_min.value);
			var ampm= document.form1.start_ampm.value;
		
		
			
			var timeDifferentPM=SelValue.substring(0,1); //Time +/- of the selected country
			var timeDifferentHr=parseFloat(SelValue.substring(1,3)); // HR DIFF of the selected country
			var timeDifferentMin=parseFloat(SelValue.substring(3,5));
			var timeDifferentTotal = parseFloat(SelValue.substring(1,5));
			if ((timeDifferentPM == '+' && locTZPM == '+')||(timeDifferentPM == '-' && locTZPM == '-')){
				if(locTotal > timeDifferentTotal){
					timeConv = parseFloat(locTZHr-timeDifferentHr);
					h = parseFloat(h) - timeConv;	
					if ((locTZMin > 0 || timeDifferentMin > 0) && (locTZMin != timeDifferentMin)){
						if (locTZMin == 0){
							minute = minute-timeDifferentMin;
							if (minute < 0) {
								minute = minute+60;
							}else{
								h = h+1;
							}
						}
						if (timeDifferentMin == 0 ){
							minute = minute+locTZMin;
							if (minute == 60 || minute > 60){
								h = h-1;
								minute = minute - 60;
							}
							else if (minute > 0 && minute < 60) {
								h = h - 1;
							}	
						}
						if( locTZMin > 0 && timeDifferentMin > 0){
							if (locTZMin > 30){
								minute = minute - 15;
								if ( minute < 0){
									h = h - 1;
									minute = minute + 60;
								}
							}else{
								minute = minute + 15;
								if ( minute > 60){
									h = h +1;
									minute = minute - 60;
								}
							}
						}						
					}
							
					if (h < 0){
						h= 12+h;
						if (ampm == 'am'){
							ampm = 'pm';
						}else{
							ampm = 'am';
						}	
					}
				}
				

				if(locTotal < timeDifferentTotal){
					h = h+(timeDifferentHr-locTZHr);
					if ((locTZMin > 0 || timeDifferentMin > 0) && (locTZMin != timeDifferentMin)){
						if (locTZMin == 0){
							minute = minute+timeDifferentMin;
							if (minute > 60) {
								h = h + 1;
								minute = minute-60;
							}						
						}
						if (timeDifferentMin == 0 ){
							minute = minute+locTZMin;
							if (minute<60){
								h = h-1;
							}else{
								minute = minute - 60;
							}
						}
						if( locTZMin > 0 && timeDifferentMin > 0){
							if (locTZMin > 30){
								minute = minute - 15;
								if ( minute < 0){
									h = h -1;
									minute = minute + 60;
								}
							}else{
								minute = minute + 15;
								if ( minute > 60){
									h = h +1;
									minute = minute - 60;
								}
							}
						}
					}
				}
				if (h < 24 && h >12){
					h= h-12;
					if (ampm == 'am'){
						ampm = 'pm';
					}else{
						ampm = 'am';
					}	
				}
				if (h >=24){
					h= h-24;
				}
			}
			if (timeDifferentPM == '+' && locTZPM == '-'){
					h = h+(locTZHr+timeDifferentHr);
					if ((locTZMin > 0 || timeDifferentMin > 0) && (locTZMin != timeDifferentMin)){
						if (locTZMin == 0){
							minute = minute+timeDifferentMin;
							if (minute > 60) {
								h = h + 1;
								minute = minute-60;
							}
						}
						if (timeDifferentMin == 0 ){
							minute = minute+locTZMin;
							if (minute<60){
								h = h-1;
							}else{
								minute = minute - 60;
							}
						}
						if( locTZMin > 0 && timeDifferentMin > 0){
							if (locTZMin > 30){
								minute = minute - 15;
								if ( minute < 0){
									h = h -1;
									minute = minute + 60;
								}
							}else{
								minute = minute + 15;
								if ( minute > 60){
									h = h +1;
									minute = minute - 60;
								}
							}
						}
					}
					if (h < 24 && h >12){
						h= h-12;
						if (ampm == 'am'){
							ampm = 'pm';
						}else{
							ampm = 'am';
						}	
					}
					if (h >=24){
						h= h-24;
					}
			}
			if (timeDifferentPM == '-' && locTZPM == '+'){
					h = 24+h-(locTZHr+timeDifferentHr);
					if ((locTZMin > 0 || timeDifferentMin > 0) && (locTZMin != timeDifferentMin)){
						if (locTZMin == 0){
							minute = minute-timeDifferentMin;
							if (minute < 0) {
								minute = minute+60;
							}else{
								h = h+1;
							}
						}
						if (timeDifferentMin == 0 ){
							minute = minute+locTZMin;
							if (minute>60){
								h = h-1;
								minute = minute - 60;
							}
						}
						if( locTZMin > 0 && timeDifferentMin > 0){
							if (locTZMin > 30){
								minute = minute - 15;
								if ( minute < 0){
									h = h - 1;
									minute = minute + 60;
								}
							}else{
								minute = minute + 15;
								if ( minute > 60){
									h = h +1;
									minute = minute - 60;
								}
							}
						}						
					}
					if (h > 12 && h <24){
						h= h-12;
						if (ampm == 'am'){
							ampm = 'pm';
						}else{
							ampm = 'am';
						}	
					}
					if (h >=24){
						h= h-24;
					}
			}
			if (minute == 60){
				h = h+1;
				minute = 0;
			}
			if (minute == 0){
				minute ='00';
			}
			if (minute > 60){
				h = h+1;
				minute = minute-60;
			}
			if (h == 0){
				h = 12;
			}
			document.form1.locTime.value=h+':'+minute+ampm;
		}
