﻿
/* CONSTANTS */
var msgShown = false;
var msgRefer = 'Please note you have not yet referred your enquiry.\r\n\r\nTo refer your enquiry, please select the \'Submit for referral\' button at the bottom of the page.\r\n\r\nAlternatively, to review your answers, simply press \'Review details\'.';
var msgFinalCheck = 'Please note you have not yet ordered your policy.\r\n\r\nTo order your policy, please select the \'Order policy\' button at the bottom of the page.\r\n\r\nTo save your quote, simply press \'Save and return to Your Elite\'.'


/* jQuery: page load function */
$(document).ready(function() {
	$("a[rel='external']").attr("target", "blank");
	$("table[class='tbl'] tr:last-child").addClass('lastRow');
	$("table[class='gv'] tr th:last-child").addClass('gvLast');
	$("table[class='MasterTable_ICON'] tr th:last-child").addClass('MasterTable_Last');
});


/* jQuery: toggles the stats of all the enabled check boxes */
function selectCheckboxes(pSetAsControl) {
	$("form :checkbox:enabled").attr('checked', $(pSetAsControl).is(':checked'));
}


/* jQuery: attaches a warning message to all links on the referral screen */
function msgAttachReferral() {
	$("a:not([class='msgIgnore'])").click(function() {
		return showMessage(msgRefer);
	});
}


/* jQuery: attaches a warning message to all links on the final check screen */
function msgAttachFinalCheck() {
	$("a:not([class='msgIgnore'])").click(function() {
		return showMessage(msgFinalCheck);
	});
}


/* displays the message once to the user */
function showMessage(pMessage) {
	if (!msgShown) {
		alert(pMessage);
		msgShown = true;
		return false;
	}
	else
		return true;
}

/* displays the final check message - Used on buttons, instead of links */
function showFinalCheckMessage() {
	return showMessage(msgFinalCheck);
}


/* title cases the text within a given textbox */
function titleCase(pTextBox) {
	var txtValue = pTextBox.value;
	if (txtValue.length > 0)
		pTextBox.value = txtValue.titleCase();
}

String.prototype.titleCase = function() {
	var words = this.split(' ');
	for (var i = 0; i < words.length; i++) words[i] = words[i].charAt(0).toUpperCase() + words[i].substr(1).toLowerCase();
	return words.join(' ');
};


// displays a Telerik popup window
function OpenRadWindow(url, clientID) {
	var oWnd;
	if (clientID != null)
		oWnd = $find(clientID);
	if (url != null)
		oWnd.setUrl(url);
	oWnd.show();
	return oWnd;
}





function ToggleItem(elementClientID) {
	var element = $get(elementClientID);
	if (element)
		element.style.display = (element.style.display == 'none') ? '' : 'none';
}

function showNoteBox(clientId, displayState) {
	var div = $get(clientId);
	if (div) {
		if (displayState)
			div.style.display = '';
		else
			div.style.display = 'none';
	}
}

function setHiddenField(clientId, fieldValue) {
	var field = document.getElementById(clientId);
	if (field != null)
		field.value = fieldValue
	else
		alert('Unable to located hidden field ' + clientId);
}

function viewHiddenField(clientId) {
	var field = document.getElementById(clientId);
	if (field != null)
		alert(field.value);
	else
		alert('Unable to located hidden field ' + clientId);
}

function UserConfirm(message) {
	return confirm(message + " \n\nAre you sure?");
}

function ConfirmDelete() {
	return ConfirmDelete(" record");
}

function ConfirmDelete(message) {
	return confirm("Delete this " + message + " \n\nAre you sure?");
}

function ProductUnavailable() {
	alert("The product that was selected is no longer available.  Please re-enter the required information.");
}

function ShowLoggedOutMessage() {
	alert("Your login session has expired due to inactivity.  Please log in again.");
}

function HistoryBack() {
	history.back();
}

function gotoUrl(destUrl) {
	location.href = destUrl;
	return false;
}



