﻿function SwitchClasses(Control, Class, Slots) {
	if (Control) {
		var CurrentControl = Control;
		var ControlToChange;

		for (var i = 1; i < Slots; i++) {
			CurrentControl = CurrentControl.nextSibling;

			if (CurrentControl.className == 'Double') {
				ControlToChange = CurrentControl.firstChild.firstChild;
			}
			else {
				ControlToChange = CurrentControl;
			}

			if (ControlToChange && ControlToChange.tagName) {
				SwitchClass(ControlToChange, Class);
			}
			else {
				i--;
			}
		}
	}
}
function SwitchClass(Control, Class) {
	if (Control) {
		try {
			var DefaultClass = Control.className;

			if ((Class != '') || !Control.DefaultClass) {
				Control.className = Class;

				if (DefaultClass.indexOf(' Today') > -1) {
					Control.className += ' Today';
				}
			}
			else {
				Control.className = Control.DefaultClass;
			}

			Control.DefaultClass = DefaultClass;
		}
		catch (e) { }
	}
}

function SelectDate(Mode, Date) {
	document.getElementById('ctl00_MainContent_ModeHiddenField').value = Mode;
	document.getElementById('ctl00_MainContent_DateHiddenField').value = Date;
	__doPostBack('ctl00_MainContent_DateHiddenField', '');
}
function SelectMonth(Date) {
	document.getElementById('ctl00_MainContent_MonthHiddenField').value = Date;
	__doPostBack('ctl00_MainContent_MonthHiddenField', '');
}
function SelectWeek() {
	document.getElementById('ctl00_MainContent_WeekHiddenField').value = document.getElementById('WeekTextBox').value;
	__doPostBack('ctl00_MainContent_WeekHiddenField', '');
}
function SelectSlot(Slot, UserId) {
	document.getElementById('ctl00_MainContent_SlotHiddenField').value = Slot;
	document.getElementById('ctl00_MainContent_SlotUserHiddenField').value = UserId;
	__doPostBack('ctl00_MainContent_SlotHiddenField', '');
}
function SelectCustomer() {
	var ReturningCustomerId = document.getElementById('ctl00_MainContent_ReturningCustomerId');
	var ReturningCustomerName = document.getElementById('ctl00_MainContent_ReturningCustomerName');
	var ReturningCustomerTextBox = document.getElementById('ctl00_MainContent_ReturningCustomerTextBox');
	var SelectedCustomer = ReturningCustomerTextBox.value;

	if (SelectedCustomer.indexOf(";") > -1) {
		var SelectedCustomerSplit = SelectedCustomer.split(";", 2);

		ReturningCustomerId.value = SelectedCustomerSplit[0];
		ReturningCustomerName.value = SelectedCustomerSplit[1];
		ReturningCustomerTextBox.value = SelectedCustomerSplit[1];
	}
	else if (SelectedCustomer != ReturningCustomerName.value) {
		ReturningCustomerId.value = "";
	}
}
function DisplayBooking(BookingId, Confirmed) {
	document.getElementById('ctl00_MainContent_BookingIdHiddenField').value = BookingId;
	document.getElementById('ctl00_MainContent_BookingConfirmedHiddenField').value = Confirmed;
	__doPostBack('ctl00_MainContent_BookingIdHiddenField', '');
}

function SortList(SortOrder) {
	document.getElementById('ctl00_MainContent_PageIndexHiddenField').value = '0';
	var SortOrderHiddenField = document.getElementById('ctl00_MainContent_SortOrderHiddenField');

	if (SortOrderHiddenField.value == SortOrder)
		SortOrderHiddenField.value += ' DESC';
	else
		SortOrderHiddenField.value = SortOrder;

	__doPostBack('ctl00_MainContent_SortOrderHiddenField', '');
}
function PageList(PageIndex) {
	document.getElementById('ctl00_MainContent_PageIndexHiddenField').value = PageIndex;
	__doPostBack('ctl00_MainContent_PageIndexHiddenField', '');
}

function ShowDiv(DivId, Milliseconds) {
	if (document.getElementById(DivId) != null)
		setTimeout("document.getElementById('" + DivId + "').style.display = 'block'", Milliseconds);
}
function HideDiv(DivId, Milliseconds) {
	if (document.getElementById(DivId) != null)
		setTimeout("document.getElementById('" + DivId + "').style.display = 'none'", Milliseconds);
	//scroll(0, 0);
}

function DisableControl(ControlId, WaitMessage) {
	var Control = document.getElementById(ControlId);

	if (!Control) return;

	Control.onclick = function() { return false; };
	Control.style.color = '#999999';

	if (WaitMessage) {
		if (Control.nodeName == 'A') {
			Control.innerHTML += ' (vänta...)';
		}
		else {
			Control.value += ' (vänta...)';
		}
	}
}
function DisableButton(Control, ValidationGroup, WaitMessage) {
	if (ValidationGroup != null && typeof (Page_ClientValidate) == 'function') {
		Page_ClientValidate(ValidationGroup);
		Page_BlockSubmit = false;
	}

	if (ValidationGroup == null || Page_IsValid) {
		setTimeout("DisableControl('" + Control.id + "', " + WaitMessage + ")", 1);
	}
}
function PopupTopFix_Old(ControlId, MpeId) {
	var Control = document.getElementById(ControlId);

	if (!Control) return;

	var Scroll = (document.all ? document.scrollTop : window.pageYOffset);

	$find(MpeId).set_Y(Scroll + 50);
}
function getScrollTop() {
	if (typeof pageYOffset != 'undefined') {
		//most browsers
		return pageYOffset;
	}
	else {
		var B = document.body; //IE 'quirks'
		var D = document.documentElement; //IE with doctype
		D = (D.clientHeight) ? D : B;
		return D.scrollTop;
	}
}
function PopupTopFix(sender, args) {
	sender.set_Y(getScrollTop() + 50);
}
