////// Inquiry.aspx functions


           function checkDate(sender, args) {
               if (sender._selectedDate < new Date()) {
                   sender._selectedDate = new Date();
                   sender._textbox.set_Value(sender._selectedDate.localeFormat(sender._format))
               }
           }

           function ValidateDate(sender, dateStr) {
               var selDate = Date.parseLocale(dateStr, sender._format);
               if (selDate == null) {
                   checkDate(sender, null);
               } else {
                  sender._selectedDate = selDate;
                  checkDate(sender, null);
              }
          }

          function getCalendarTo() {
              return Sys.Application.findComponent("edTo_CalendarExtender");
          }
          function getCalendarFrom() {
              return Sys.Application.findComponent("edFrom_CalendarExtender");
          }
          

           function ValidateFromDate(validateOnly) {
               ValidateDate(getCalendarFrom(), document.getElementById("edFrom").value);
               CompareDates();
               if (!validateOnly) {
                   setDaysCombo();
               }
               PageMethods.getTickerByDate(document.getElementById("edFrom").value, onTickerSearchComplete);
           }

           function onTickerSearchComplete(results) {
               var fill = document.getElementById("myhtmlticker");
               fill.innerHTML = results;
               richhtmlticker.defineDefaults();
           }
 
           function addDays(myDate, days) {
             var result=removeTime(myDate);
             result.setDate(myDate.getDate()+days);
             return result;
           }

           function CompareDates() {
               toCalendar = getCalendarTo();
               toDate = removeTime(toCalendar._selectedDate);
               fromDate = removeTime(getCalendarFrom()._selectedDate);
               if (fromDate >= toDate) {
                   toDate = addDays(fromDate, 1);
                   toCalendar._selectedDate = toDate;
                   toCalendar._textbox.set_Value(toDate.localeFormat(toCalendar._format))
               }                          
           }
           
           
           function ValidateToDate() {
               ValidateDate(getCalendarFrom(), document.getElementById("edFrom").value);
               ValidateDate(getCalendarTo(), document.getElementById("edTo").value);
               CompareDates();
               setDaysCombo();
           }

           function AdjustDeparture() {
               ValidateFromDate(true);
               d = parseInt(document.getElementById("cbDays").value);
               toDate = addDays(fromDate, d);
               toCalendar._selectedDate = toDate;
               toCalendar._textbox.set_Value(toDate.localeFormat(toCalendar._format))
           }

           function removeTime(srcDate) {
               //result = Date.parse(
               var dt = srcDate.getDate();
               var mm = srcDate.getMonth();
               var yy = srcDate.getFullYear();
               var result = new Date(0);
               result.setFullYear(yy, mm, dt);
			   result.setHours(0); //daylight problems
               return result;
           }
  
		   function days_between(date1, date2) {

  			 // The number of milliseconds in one day
			 var ONE_DAY = 1000 * 60 * 60 * 24

			 // Convert both dates to milliseconds
			 var date1_ms = date1.getTime()
			 var date2_ms = date2.getTime()

			 // Calculate the difference in milliseconds
			 var difference_ms = Math.abs(date1_ms - date2_ms)
			
			  // Convert back to days and return
			 return Math.round(difference_ms/ONE_DAY)
           }
  
           function setDaysCombo() {
             var d1 = removeTime(getCalendarTo()._selectedDate);
             var d2 = removeTime(getCalendarFrom()._selectedDate);
			 var diff = (days_between(d1, d2));
             document.getElementById("cbDays").selectedIndex = diff - 1;
           }

           function callPopup() {
               window.open("ShowBriefPrices.aspx", "_blank", "status=0,toolbar=0,location=0");
           }


////// End Inquiry.aspx /////

////// ShowBriefPrices.aspx /////

           var image, name;
           function pop(image, name) {
               var win = window.open("", "", "width=600, height=500");
               win.document.write("<html><body><head><title>"+name+"</title>");
               win.document.write("<link href=\"css/style.css\" rel=\"stylesheet\" ><link href=\"css/color.css\" rel=\"stylesheet\" >");
               win.document.write("</head>");
               win.document.write("<body class=\"pop\" >");
               win.document.write("</div><img src=\"Img/Rooms/Screens/" + image + ".jpg\" width=\"500\" height=\"350\" >");
               win.document.write("<input type=\"button\" onclick=\"window.close();\" value=\"Close Window\">");
               win.document.write("</body>");
               win.document.write("</html>");
               win.document.close();
           }
		  
			var d = document;
		    var prev = 'all';
			function tab(id) {
				d.getElementById(prev).className = 'tablist';
				d.getElementById(id).className = 'tablistSelected';

				d.getElementById('_'+prev).style.display = 'none';
				d.getElementById('_'+id).style.display = 'block';
				d.getElementById('_'+id).blur();
				prev = id;

				d.getElementById(id).blur();

				return false;
			}


		   
////// End ShowBriefPrices.aspx /////		  

////// VoucherSelection.aspx //////////		  
    function ValidateNumber(inputField, errorMessage) {
    try {
        var inpVal = parseInt(inputField.value, 10);
        if (isNaN(inpVal) || inpVal < 0) {
            var msg = errorMessage;
            var err = new Error(msg);
            if (!err.message) {
                err.message = msg;
            }
            throw err;
        }
    } catch (e) {
        alert(e.message);
        inputField.focus();
        inputField.select();
		return false;
    }
	return true;
}

	function RecalcTotal () {
	  var total = 0;
	  var lists = document.getElementsByTagName("input");
	  for (var i = 0; i < lists.length; i++) {
		var ctrl = lists[i];
		if (ctrl.id.indexOf("Quantity") ==0 ){
		  if (!ValidateNumber(ctrl, errorMessage())){return false;}
		  var priceCntrlName = "Price" + ctrl.id.substring(8, 15);
		  var priceCntrl = document.getElementById(priceCntrlName);
		  total += ctrl.value * priceCntrl.value;
		}
		if (ctrl.name.indexOf("_Quantity") >=0  && ctrl.name.indexOf("Cust") == 0){
		  if (ctrl.checked){
		    var voucherID = ctrl.name.replace("_Quantity", "");
			voucherID = voucherID.replace("Cust", "");
			var priceCntrlName = "Price" + voucherID;
			var priceCntrl = document.getElementById(priceCntrlName);
		    total += (priceCntrl.value * 1);
		  }
		}
	  }
	  document.getElementById("orderTotal").innerHTML = total.toFixed(2);
	  return total;
	}
	////// End ShowBriefPrices.aspx /////

///// registraion.aspx //////////
	function checkBSDate(sender, args) {
	    if (sender._selectedDate > new Date()) {
	        sender._selectedDate = new Date();
	        sender._textbox.set_Value(sender._selectedDate.localeFormat(sender._format))
	    }
	}

	function ValidateBSDate(sender, dateStr) {
	    var selDate = Date.parseLocale(dateStr, sender._format);
	    if (selDate == null) {
	        checkBSDate(sender, null);
	    } else {
	        sender._selectedDate = selDate;
	        checkBSDate(sender, null);
	    }
	}

	function getBSCalendarTo() {
	    return Sys.Application.findComponent("TabContainer2_TabBonuspoint_edBSTo_CalendarExtender");
	}

	function getBSCalendarFrom() {
	    return Sys.Application.findComponent("TabContainer2_TabBonuspoint_edBSFrom_CalendarExtender");
	}

	function CompareBSDates() {
	    toBSCalendar = getBSCalendarTo();
	    toDate = removeTime(toBSCalendar._selectedDate);
	    fromDate = removeTime(getBSCalendarFrom()._selectedDate);
	    if (fromDate >= toDate) {
	        toDate = addDays(fromDate, 0);
	        toBSCalendar._selectedDate = toDate;
	        toBSCalendar._textbox.set_Value(toDate.localeFormat(toBSCalendar._format))
	    }
	}

	function ValidateBonusStatementFromDate() {
	    ValidateBSDate(getBSCalendarFrom(), document.getElementById("TabContainer2_TabBonuspoint_edBSFrom").value);
	    CompareBSDates();
	}

	function ValidateBonusStatementToDate() {
	    ValidateBSDate(getBSCalendarTo(), document.getElementById("TabContainer2_TabBonuspoint_edBSTo").value);
	    CompareBSDates();
	}

	///// End registraion.aspx //////////

	//Table Reservations//
	function ValidateTRDate(validateOnly) {
	   ValidateDate(getCalendarFrom(), document.getElementById("edFrom").value);
	}

	//////////////////////
	var effect = "clip";
	function s8Toggle(id) {
      $("#" + id).toggle(effect);        
	}
	//////////////////////

