%@ include file="/includes/tagLibs.jsp" %>
//Author: Mag Leahy, 04/03/2008
//Description: Clears generic form message and updates with text as error appear and dissapear.
//Parameters: Number of errors on the form from the jQuery validator, form error container id
function generalFormError(numErrors, formErrorContainer)
{
var strGeneralErrorContainerPrefix = '';
var strGeneralErrorContainerSuffix = '';
var strGeneralErrorPrefix = '';
var strGeneralErrorSuffix = ''
var strGeneralErrorsSuffix = ''
$(formErrorContainer).html("");
if (numErrors == 1)
{
$(formErrorContainer).html(strGeneralErrorContainerPrefix + strGeneralErrorPrefix + numErrors + strGeneralErrorSuffix + strGeneralErrorContainerSuffix);
}
else if (numErrors > 1)
{
$(formErrorContainer).html(strGeneralErrorContainerPrefix + strGeneralErrorPrefix + numErrors + strGeneralErrorsSuffix + strGeneralErrorContainerSuffix);
}
}
//Opens links with rel="external" in a new window
function externalLinks()
{
if (!document.getElementsByTagName) return;
var links = document.getElementsByTagName("a");
for (var i=0; i < links.length; i++)
{
var link = links[i];
if (link.getAttribute("href") && link.getAttribute("rel") == "external") link.target = "_blank";
}
}
//Adds js for print page to print text that stays on the page regardless of js on/off
//If a link is purely for
function printPageLinks()
{
if (!document.getElementsByTagName) return;
var spans = document.getElementsByTagName("span");
for (var i=0; i < spans.length; i++)
{
var span = spans[i];
if ($(span).attr("class") == "js-print")
{
$(span).wrap('');
$(span).parent('a').click( function() { window.print(); return false; } );
}
}
}
//Hides for JS version by reference to .js-hide
function hideForJS()
{
$('.js-hide').css({ position:"absolute", left:"-99999px" });
}
$(document).ready(function (){
externalLinks();
printPageLinks();
hideForJS();
});
//Mag Leahy 20080604: This function goes upwards in seach of element with class of strErrorContainerClass's value
//Arguments: Element that is causing the error
//There is limit of numMaxAscensions to limit steps up. This may need to be revisited.
var numCounter = 0, numMaxAscensions = 4, strErrorContainerClass = 'er', strErrorElement = 'body';
function findErrorDiv(element){
while (numCounter < numMaxAscensions){
numCounter++;
var bolErrorHolder = element.hasClass(strErrorContainerClass);
if (bolErrorHolder){numCounter = 0; return element;}
else element = element.parent();
}
return $(strErrorElement); //If there's no match for error placement return default tag.
}
//Mag Leahy 20080718: JQuery Custom Methods for validation
//http://docs.jquery.com/Plugins/Validation/Validator/addMethod#namemethodmessage
if(jQuery.validator) //Error checks that validation js is on the page
{
//addMehtod: money checks if the value entered is numeric but allows "," and "£" in their correct use and 2 decimal places (optional).
jQuery.validator.addMethod("money", function(value, element) {return this.optional(element) || /^£?((\d{1,}(\.\d{1,2})?$)|((\d{1,3}(\,\d{3})*)((\.\d{2})?)$))/.test(value);}, "Please enter a money value (e.g. 100,000.00 or 100000)");
//addMehtod: moneywhole checks if the value entered is numeric but allows "," and "£" in their correct use but decimal places are not allowed.
jQuery.validator.addMethod("moneywhole", function(value, element) {return this.optional(element) || /^£?((\d{1,}$)|((\d{1,3}(\,\d{3})*)$))/.test(value);}, "Please enter a whole money value (e.g. 100,000 or 100000)");
}