var appRoot = "";

function urlEncode(sStr) {
	return escape(sStr).replace(/\+/g, '%2C').replace(/\"/g,'%22').replace(/\'/g, '%27');
}

function popup(url, name, width, height, params) {
	var properties = "";
	properties += "width=" + width;
	properties += ",height=" + height;
	if (params) {
		properties += "," + params;
	}
	var w = window.open(url, name, properties);
	return w;
}

function messagePopup(message_id) {
	var width = 470;
	var height = 200;
	var url = appRoot + "/common/message_popup.aspx?id=" + message_id;
	return popup(url, "message_popup", width, height);
}

function calendar(name, allowPast, date, minDate) {
	var width = 250;
	var height = 200;
	var params = "input_name=" + urlEncode(name) + 
		"&allow_past=" + urlEncode(allowPast) + 
		"&date=" + urlEncode(date) + 
		"&min_date=" + urlEncode(minDate);
	var url = appRoot + "/common/calendar.aspx?" + params;
	return popup(url, "calendarPopup", width, height);
}

function employeeViewTimeoffComments(id) {
	var width = 670;
	var height = 450;
	return popup(appRoot + "/employee/timeoff_view_comments.aspx?id=" + id, "employeeCommentsPopup", width, height);
}

function adminViewTimeoffComments(id) {
	var width = 670;
	var height = 450;
	return popup(appRoot + "/admin/timeoff_view_comments.aspx?id=" + id, "adminCommentsPopup", width, height);
}

function readMessagesView() {
	var width = 670;
	var height = 620;
	return popup(appRoot + "/common/read_messages_popup.aspx", "readMessagesPopup", width, height, "scrollbars=yes");
}

function absencesPopup(employeeId) {
	var width = 580;
	var height = 400;
	return popup(appRoot + "/common/absence_popup.aspx?employee_id=" + employeeId, "absencePopup", width, height);
}

function dailyAbsencesPopup(employeeId, day) {
	var width = 580;
	var height = 400;
	return popup(appRoot + "/common/daily_absence_popup.aspx?employee_id=" + employeeId + "&day=" + day, "dailyAbsencePopup", width, height);
}

function confirmAndRedirect(message, url) {
	if (confirm(message)) {
		window.location.href = url;
	}
}

function changePasswordPopup() {
	var width = 470;
	var height = 250;
	return popup(appRoot + "/common/change_password.aspx", "changePasswordPopup", width, height);
}

function pAdminChangePasswordPopup(id) {
	var width = 670;
	var height = 350;
	return popup(appRoot + "/payroll_admin/user_change_password.aspx?id=" + id, "paChangePasswordPopup", width, height);
}
