// ############################################################################
// ##
// ##  CUSTOM WEBSITE FUNCTIONS
// ##  (i.e. not standard white site functions)
// ##
// ############################################################################

// Put custom functions for your website here.

function InitialiseJQFader() {
    $(document).ready(function () {
        $('.slideshow').cycle({
            fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
        });
        $('#RotatorContent').cycle({
            fx: 'fade',
            delay:  -400, 
            speed:   2000, 
            timeout: 6000 
        });
    });
}
// ############################################################################
// ##
// ##  STANDARD WHITE SITE FUNCTIONS
// ##
// ############################################################################

// ####################################
// Navigation
// ####################################

// ====================
// Function:    NavPullDown
//
// Purpose:     Go to a URL that is selected from a form a pull-down form field
//
// Input:       strFormName - The ID of the form being used to select naviation
//              strFieldName - The ID of the field with URL select options
//
// Output:      Navigates to selected URL.
//
// Assumptions: -
//
// History:     DDSN created back in the Distant Past
// ====================
function NavFormSelect(strFormName,strFieldName) {
	intSelected = document[strFormName].elements[strFieldName].options.selectedIndex;
	strURL = document[strFormName].elements[strFieldName].options[intSelected].value;
	document[strFormName].elements[strFieldName].options.selectedIndex = 0;
	if (strURL != "") {
		location.href = strURL;
	}
}

// ====================
// Function:    InitNav
//              Note: InitNav must be called after menu list is created.
//
// Purpose:     Assigns classes to certain events for Internet Explorer 6.
//              (IE6 does not fully support CSS standards.)
//
// Input:       -
//
// Output:      -
//
// Assumptions: -
//
// History:     200512 Code from htmldog.com
//              200512 RW Turned into a function for nicer modularity
// ====================
function InitNav(strListID) {
	sfHover = function() {
		var sfEls = document.getElementById(strListID).getElementsByTagName("LI");
		for (var i=0; i < sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
	// Only executes in IE
	if (window.attachEvent) {
		window.attachEvent("onload", sfHover);
	}
}
	
// ####################################
// Windows & Alerts
// ####################################

// ====================
// Function:    Popup
//
// Purpose:     Open a popup window with a series of option settings.
//
// Input:       strPage - The URL of the page to open in the popup window.
//              intWidth - The window width in pixels 
//              intHeight - The window height in pixels
//              strID - The ID of the popup window. (This is important if the
//                window may be called on by other functions or if there are
//                multiple popup windows in a site.)
//              strScrollbars - Switch visible scrollbars on/off ("yes"/"no")
//              strLocation - Switch visible location bar on/off ("yes"/"no")
//              strToolbar - Switch visible toolbar on/off ("yes"/"no")
//              strStatus - Switch visible status bar on/off ("yes"/"no")
//              strResizable - Window is resizable or not ("yes"/"no")
//
// Output:      Window opens containing the specified URL.
//
// Assumptions: -
//
// History:     DDSN created back in the Distant Past
// ====================
function Popup(strPage,intWidth,intHeight,strID,strScrollbars,strLocation,strToolbar,strStatus,strResizable) {
	if (!strPage) {
		strPage = "/";
	}
	if (!intWidth) {
		intWidth = 500;
	}
	if (!intHeight) {
		intHeight = 320;
	}
	if (!strID) {
		strID = "PopupWindow";
	}
	if (!strScrollbars) {
		strScrollbars = "yes";
	}
	if (!strLocation) {
		strLocation = "no";
	}
	if (!strToolbar) {
		strToolbar = "no";
	}
	if (!strStatus) {
		strStatus = "no";
	}
	if (!strResizable) {
		strResizable = "yes";
	}
	//if (isLoaded == 0) {
	//	location.reload();
	//}
	idPopup = window.open(strPage,strID,"width="+intWidth+",height="+intHeight+",scrollbars="+strScrollbars+",location="+strLocation+",toolbar="+strToolbar+",status="+strStatus+",resizable="+strResizable);
	
	if (window.focus) {
		idPopup.focus();
	}
	return false;
}

// ====================
// Function:    PopdownLink
//
// Purpose:     Open a link in a popup window in a specified main window and
//              close the popup window. If the specified link window does not
//              exist it is created. If no window is specified the link is
//              targeted to the original opener of the popup window.
//
// Input:       strURL - The URL of the page to open
//              strWindowID - The ID of the window in which to open the link
//
// Output:      Navigates to selected URL in selected window and closes current
//              window.
//
// Assumptions: -
//
// History:     DDSN created back in the Distant Past
//              2004 Multiple window targets added. (Previously could only
//                   target the opener.)
// ====================
function PopdownLink(strURL,strWindowID) {
	if (!strWindowID) {
		top.opener.location.href = strURL;
    } else {
		if (strWindowID.location) {
			strWindowID.location.href = strURL;
	    } else {
			window.open(strURL,strWindowID);
	    }
    }
	top.close();
}

// ====================
// Function:    CS
//
// Purpose:     Display a "coming soon" message for sections of a website that
//              have not been created yet. This function is sometimes used in
//              development to make links active before a site is finished.
//
//              Note: This is an evil funciton, it should not be used! It
//              encourages bad development habits.
//
// Input:       -
//
// Output:      Show a "coming soon" message.
//
// Assumptions: -
//
// History:     DDSN created back in the Distant Past
// ====================
function CS() {
	alert("That function is coming soon.");
}

// ####################################
// Site Search Form
// ####################################

// ====================
// Function:    RequireKeywords
//
// Purpose:     Checks any search form to make sure keywords are entered before
//              the form can be submitted. 
//
// Input:       strFormName - The ID of the form with the keywords field in it
//              strFieldName - The ID of the keywords field within the form 
//
// Output:      Give an error if no keywords are presented.
//
// Assumptions: -
//
// History:     20040109 RW Created to replace local code in site templates.
// ====================
function RequireKeywords(strFormID,strFieldName) {
	if (document.forms[strFormID].elements[strFieldName].value.length <= 3) {
		alert("Please alter your requested keyword(s) in the search form.\nThe search phrase must be 3 characters or more in length.")
		return false;
	}
}

// ====================
// Function:    SearchKeywordsFieldOnClick, SearchKeywordsFieldOnBlur, SearchKeywordsFieldOnLoad
//
// Purpose:     Triggered when the site search form keywords field is clicked,
//              blurred, or loaded. Intended to help control behaviour of the
//              keywords field. 
//
// Input:       this - The keywords field object.
//
// Output:      Controls behaviour of the search keywords field when clicked.
//
// Assumptions: -
//
// History:     20080505 RW Created
// History:     20082306 AT Updated the value message
// ====================
function SearchKeywordsFieldOnClick(objField) {
    if(objField.value=='Enter search keywords') {
        objField.value = '';
    }
}
function SearchKeywordsFieldOnBlur(objField) {
    if(objField.value=='') {
        objField.value = 'Search';
    }
}
function SearchKeywordsFieldOnLoad(objField) {
    objField.value = 'Search';
}

// ####################################
// Image Manipulation
// ####################################

// ====================
// Function:    ImageSwap
//
// Purpose:     Swap any image to another.
//
// Input:       strImageID - ID of the image being swapped
//              strNewImageSrc - Source of the new image being loaded
//
// Output:      Swaps images.
//
// Assumptions: Images with all specified IDs exist and are pre-loaded.
//
// History:     DDSN created back in the Distant Past
// ====================
function ImageSwap(strImageID,strNewImageSrc) {
	if (document.images) {
		document.images[strImageID].src = eval(strNewImageSrc+".src");
	}
}

// ====================
// Function:    ImageSwapFX
//
// Purpose:     Swap any image to another using an optional fade effect. Can
//              also be called with the transition effect disabled, i.e. just
//              swap the images.
//
// Input:       strImageID - ID of the image being swapped
//              strNewImageSrc - Source of the new image being loaded
//              blnDisableTrans - Switch the transition off or on (1/0)
//
// Output:      Swaps images with optional fade effect.
//
// Assumptions: - Images with all specified IDs exist and are pre-loaded.
//              - Requires fading transition style to be set first on image tag
//              - Only works for IE5.5+ but falls back nicely
//              - Javascript Globals: blnToggleTrans
//
// History:     2003 DDSN Created
//              2004 Updated with more standard naming structures
// ====================
function ImageSwapFX(strImageID,strNewImageSrc,blnDisableTrans) {
	if (blnDisableTrans || !document.images[strImageID].filters || blnIE50) {
		if (document.images) {
			document.images[strImageID].src = eval(strNewImageSrc+".src");
		}
	} else {
		// After setting Apply, changes to the object are not displayed
		// until Play is called.
		document.images[strImageID].filters[0].Apply();

		if (blnToggleTrans) {
			blnToggleTrans = 0;
			document.images[strImageID].src = eval(strNewImageSrc+".src");
		} else {
			blnToggleTrans = 1;
			document.images[strImageID].src = eval(strNewImageSrc+".src");
		}
		document.images[strImageID].filters[0].Play();
	}
}

// ####################################
// Form Handling
// ####################################

function SetDefaultFieldValue(strForm,strElement,strValue,blnFocus) {

	var strSubscribeValue = document.forms[strForm].elements[strElement].value;

	if ( blnFocus ) {
		if ( strSubscribeValue == strValue ) {
			document.forms[strForm].elements[strElement].value = "";
		}
	} else {
		if ( strSubscribeValue == "" ) {
			document.forms[strForm].elements[strElement].value = strValue;
		}
	}

}

// ####################################
// DOM/div Manipulation
// ####################################

// ====================
// Function:    getObj
//
// Purpose:     Returns string for access to passed in object style attributes
//
// Input:       ID of object
//
// Output:      Returns string for access to passed in object style attributes
//
// Assumptions: -
//
// History:     SC 2006-05-15
function getObj(name) {
	if (document.getElementById) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	} else if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	} else if (document.layers) {
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}


// ====================
// Function:    CreateSecondaryHeight
//
// Purpose:     Sets the height of the Secondary container to be equal to Tertiary minus Primary.
//
// Input:       strPageObjects - Comma separated list of object IDs that should have their heights compared and readjusted.
//
// Output:      Updates the height of the Secondary container if the Tertiary is larger than Primary and Secondary combined..
//
// Assumptions: GetObjectHeight()
//
// History:     20071115 PW & JK Created
// ====================
function CreateSecondaryHeight() {

	if (document.getElementsByTagName('body')[0].id != 'homepage') {
		strPageObjects = "Primary,Secondary,Tertiary-Inner";
		var arrObjectHeight = new Array();
	
		if (strPageObjects) {
			arrPageObjects = strPageObjects.split(",");
		}
	
		if (arrPageObjects) {
			// Find the height of the tallest object.
			for (i = 0; i < arrPageObjects.length; i++) {
				arrObjectHeight[i] = GetObjectHeight(arrPageObjects[i]);
			}
		
			intContent =  arrObjectHeight[0] + arrObjectHeight[1];
			intMenu = arrObjectHeight[2];
		
			if (intContent < intMenu) {
				arrObjectHeight[1] = (arrObjectHeight[2] - arrObjectHeight[0]);
				document.getElementById(arrPageObjects[1]).style.height = arrObjectHeight[1] + 50 + "px";
			}
		}
	}
}

// ====================
// Function:    GetObjectHeight
//
// Purpose:     Returns the height of any passed in block level object
//
// Input:       ID of item
//
// Output:      Returns the height of any passed in block level object
//
// Assumptions: -
//
// History:     SC 2006-05-15
// ====================
function GetObjectHeight(objectRef) {
	var intHeight = -1;

	if (document.getElementById) {
		if (document.getElementById(objectRef)) {
			intHeight = eval(document.getElementById(objectRef).offsetHeight);
		}
	} else if (document.all) {
		if (document.all[objectRef]) {
			intHeight = document.all[objectRef].scrollHeight;
		}
	} else if (document.layers) {
		if (document[objectRef]) {
			intHeight = document[objectRef].clip.bottom;
		}
	}

	return intHeight;
}

// ====================
// Function:    SetUniformHeight
//
// Purpose:     Sets a number of page objects to a uniform height, being the
//              maximum height of any of the given objects.
//
// Input:       strPageObjects - Comma separated list of object IDs that should
//              be set to a uniform height.
//
// Output:      Updates the height of the given objects.
//
// Assumptions: GetObjectHeight()
//
// History:     20060823 RW Created
// ====================
function SetUniformHeight(strPageObjects) {
	intMaxHeight = 0;

	if (strPageObjects) {
		arrPageObjects = strPageObjects.split(",");
	}

	if (arrPageObjects) {
		// Find the height of the tallest object.
		for (i = 0; i < arrPageObjects.length; i++) {
			intThisHeight = GetObjectHeight(arrPageObjects[i]);
			if (intThisHeight > intMaxHeight) {
				intMaxHeight = intThisHeight;
			}
		}

		// Set all the objects to the same (maximum) height if a height larger
		// than 0 was found.
		if (intMaxHeight > 0 ) {
			for (i = 0; i < arrPageObjects.length; i++) {
				//if (blnIE)  {
				//	strMaxHeight = intMaxHeight;
				//} else {
					strMaxHeight = intMaxHeight + 'px';
				//}
				if(document.getElementById(arrPageObjects[i])) {
					document.getElementById(arrPageObjects[i]).style.height = strMaxHeight;
				}
			}
		}
	}
}

// ====================
// Function:    fixActivexClick
//
// Purpose:     Stops the active content "click to activate" annoyance for IE7.
//
// Input:       -
//
// Output:      Removes the "click to activate" from <object> tags in IE.
//
// Assumptions: -
//
// History:     - ???
//		- 20090702 GR it was commented out but called on every page which produced JS errors.
//			I uncommented it
// ====================
// Active Content "first click" fix for IE
function fixActivexClick() {
	objectTags = document.getElementsByTagName("object");
	for (var i = 0; i < objectTags.length; i++) {
		objectTags[i].outerHTML = objectTags[i].outerHTML;
	}
}

// ====================
// Function:    GetCSSProperty
//
// Purpose:     Allows retrieval of a CSS property from a separately specified style sheet.
//
// Input:       objElement - The element for which you want to retrive a CSS property
//              strCSSProperty - The JS/CSS style name, e.g. fontSize
//              strCSSPropertyLabel - The style label as though you wrote it in a stylesheet, e.g. font-size
//
// Output:      Returns the CSS property value. Note: Raw value in IE, computed value in NS!
//
// Assumptions: -
//
// History:     20080514 RW Created
// ====================
function GetCSSProperty(objElement, strCSSProperty, strCSSPropertyNS) {
    if (objElement.currentStyle) { //if IE5+
        return objElement.currentStyle[strCSSProperty];
    } else if (window.getComputedStyle) { //if NS6+
        var objElementStyle = window.getComputedStyle(objElement, "");
        return objElementStyle.getPropertyValue(strCSSPropertyNS);
    }
}

// ====================
// Function:    ShowLoginAlert
//
// Purpose:     Specific function for NTAA login alert
//
// Input:       objRef - ID of object
//              blnAction - 'visible' OR 'hidden'
//
// Output:      None.
//
// Assumptions: -
//
// History:     20061026 - SC Created
// ====================
function ShowLoginAlert() {

    var strPageContentHeight = GetObjectHeight('page-content');

    document.getElementById('cart-page-alert').style.top = eval(strPageContentHeight - 3) + "px"; ;

    LayerVisibility('cart-page-alert', 'visible');

}

// ====================
// Function:    LayerVisibilityDelay
//
// Purpose:     Sets a given delay on changing visibility of a DIV.
//
// Input:       objRef - ID of object
//              blnAction - 'visible' OR 'hidden'
//		intDelay - Delay time in milliseconds
//
// Output:      None.
//
// Assumptions: -
//
// History:     20061026 - SC Created
// ====================
var intTimer;

function LayerVisibilityDelay(objRef, blnAction, intDelay) {

    clearTimeout(intTimer);

    intTimer = setTimeout("LayerVisibility('" + objRef + "','" + blnAction + "')", intDelay);

}

// ####################################
// Layer Manipulation
// ####################################

// ====================
// Function:    LayerVisibility
//
// Purpose:     Turn visibility of any layer on or off.
//
// Input:       strLayerID - ID of the layer being altered
//              strState = "visible" or "hidden"
//
// Output:      Turns specified layer on or off.
//
// Assumptions: Specified layer exists in document hierarchy.
//
// History:     DDSN created back in the Distant Past
// ====================
function LayerVisibility(strLayerID, strState) {

    clearTimeout(intTimer);

    if (blnNS4) {
        if (document.layers[strLayerID]) {
            document.layers[strLayerID].visibility = strState;
        }
    }
    else if (blnDOM) {
        if (document.getElementById(strLayerID)) {
            document.getElementById(strLayerID).style.visibility = strState;
        }
    }
    else if (blnIE) {
        if (document.all[strLayerID]) {
            document.all[strLayerID].style.visibility = strState;
        }
    }
}

// ====================
// Function:    LayerDisplay
//
// Purpose:     Turn display of any layer on or off.
//
// Input:       strLayerID - ID of the layer being altered
//              strState = "visible" or "hidden"
//
// Output:      Turns specified layer on or off.
//
// Assumptions: Specified layer exists in document hierarchy.
//
// History:     DDSN created back in the Distant Past
// ====================
function LayerDisplay(strLayerID, strState) {
    if (blnNS4) {
        if (document.layers[strLayerID]) {
            document.layers[strLayerID].display = strState;
        }
    }
    else if (blnDOM) {
        if (document.getElementById(strLayerID)) {
            document.getElementById(strLayerID).style.display = strState;
        }
    }
    else if (blnIE) {
        if (document.all[strLayerID]) {
            document.all[strLayerID].style.display = strState;
        }
    }
}

// ####################################
// Printing
// ####################################

// ====================
// Function:    LoadVBPrinter
//
// Purpose:     Load Visual Basic printing commands for VB enabled browsers.
//
// Input:       -
//
// Output:      Loads (writes out) visual basic printing functions.
//
// Assumptions: Javascript Globals: blnIE, blnCanPrint, blnMac
//
// History:     DDSN created back in the Distant Past
// ====================
function LoadVBPrinter() {
	if (blnIE && !blnCanPrint && !blnMac) with (document) {
		writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
		writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
		writeln('Sub window_onunload');
		writeln('    On Error Resume Next');
		writeln('    Set WB = nothing');
		writeln('End Sub');
		writeln('Sub vbPrintPage');
		writeln('    OLECMDID_PRINT = 6');
		writeln('    OLECMDEXECOPT_DONTPROMPTUSER = 2');
		writeln('    OLECMDEXECOPT_PROMPTUSER = 1');
		writeln('    On Error Resume Next');
		writeln('    WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
		writeln('End Sub');
		writeln('<' + '/SCRIPT>');
	}
}

// ====================
// Function:    PrintPage
//
// Purpose:     Opens the print dialog window or shows a fallback message for
//              unsupported browsers
//
// Input:       -
//
// Output:      Opens the print dialog window or shows a fallback message for
//              unsupported browsers.
//
// Assumptions: Javascript Globals: blnCanPrint, blnIE, blnMac
//
// History:     DDSN created back in the Distant Past
// ====================
function PrintPage() {
	if (blnCanPrint) {
		window.print();
	} else if (blnIE && !blnMac) {
		vbPrintPage();
	} else {
		alert("Your web browser does not appear to support the automatic\nPrint function. To print this page, please select the \"Print\"\noption from the \"File\" menu of your web browser.");
	}
}

// Load Visual Basic printing commands for VB enabled browsers
//LoadVBPrinter()

// ####################################
// Accessibility
// ####################################

// ====================
// Function:    TextSize
//
// Purpose:     Allows the user to alter the text size in the site style sheet.
//
// Input:       '-' to decrease the text size.
//              '+' to increase the text size.
//
// Output:      Alters the base text size on the <body> tag.
//
// Assumptions: -
//
// History:     20080515 RW Created
// ====================
function TextSize(strIncrement) {
   
    //intTextSize = document.getElementsByTagName("body")[0].style.fontSize;
    //intTextSize = document.body.style.fontSize;
    strTextSize = GetCSSProperty(document.body,"fontSize","font-size");
    
    if (strTextSize.indexOf("em") > 0) {
        strTextSizeUnit = "em";
        intTextSize = strTextSize.substring(0,strTextSize.length-2);
    } else if (strTextSize.indexOf("px") > 0) {
        strTextSizeUnit = "px";
        intTextSize = strTextSize.substring(0,strTextSize.length-2);
    } else if (strTextSize.indexOf("%") > 0) {
        strTextSizeUnit = "%";
        intTextSize = strTextSize.substring(0,strTextSize.length-1);
    } else {
        strTextSizeUnit = "%";
        intTextSize = "100";
    }

    if (strIncrement == '-') {
        intTextSize = intTextSize / 1.2;
    } else if (strIncrement == '+') {
        intTextSize = intTextSize * 1.2;
    }
    
    document.body.style.fontSize = intTextSize + strTextSizeUnit;
}

// ####################################
// ASP.Net Enhancements & Hacks
// ####################################

// The following functions are loaded by ASP.Net in WebResource.axd when a
// server side form is used, but WebResource.axd is not loaded until the 
// last element of the page! So if an event fires on the page (like a 
// keypress on a form element) that requires one of these functions, a 
// Javascript error will be generated. Quite silly! Defining these functions
// in our global file (loaded in the header) as blank functions at least
// means that the same behaviour will happen for these events as happens when
// Javascript is turned off completely, rather than an ugly error.
function WebForm_FireDefaultButton(event, target) {
}

function Body_OnLoad() {
	if (window.on_load&&(typeof window.on_load=="function")) window.on_load();
}

// ####################################
// Custom Fuctions
// ####################################

//var oldprice = new Array();	
	
// ====================
// Function:    updatePriceFields
//
// Purpose:     Update "summary" price fields for one or two fields when
//              user select new price from some "selection" element
//
// Input:       
//          -   el - "selection" object (e.g. dropdown, radio etc), 
//          -   price - numeric price,
//          -   f1 - name of first "summary" field,
//          -   f2 - name of second "summary" field
//
// Output:      Alters values for one or two "summary" fields
//
// Assumptions:
//          -   There is only one form on the page
//          -   Value for oldprice[] Array is prepopulated (with 0?)
//
// History:     
//		20080815 GR created
//		20080825 GR updated to NOT use oldprice Array which created problem if user hit back button
// ====================
function updatePriceFields(el, price, f1, f2) {
    var ElementName;
    
    var f = document.forms[0];
  
    var ElementName = '';
    //need to combine morning and afternoon values for Wednesday 28th
    if(el.name == 'safety_conf_20101027_morning' || el.name == 'safety_conf_20101027_afternoon'){
        //
        ElementName = 'safety_conf_20101027';
    }
    else {
        ElementName = el.name;
    }
  
  
    var valdif = 1 * price - 1 * f.elements["old" + ElementName].value;
    if (f.elements["oldsafety_conf_FullReg"].value == 0) {

        if (f1 && f.elements[f1]) {
            if (!f.elements[f1].value) {
                f.elements[f1].value = 0;
            }
            f.elements[f1].value = 1 * f.elements[f1].value + 1 * valdif;
        }
        if (f2 && f.elements[f2]) {
            if (!f.elements[f2].value) {
                f.elements[f2].value = 0;
            }
            f.elements[f2].value = 1 * f.elements[f2].value + 1 * valdif;
        }
        //f.elements["old" + el.name].value = price;
    } else if (el.name == "safety_conf_FullReg" || el.name.indexOf("conf") == -1) {
        if (f1 && f.elements[f1]) {
            if (!f.elements[f1].value) {
                f.elements[f1].value = 0;
            }
            f.elements[f1].value = 1 * f.elements[f1].value + 1 * valdif;
        }
        if (f2 && f.elements[f2]) {
            if (!f.elements[f2].value) {
                f.elements[f2].value = 0;
            }
            f.elements[f2].value = 1 * f.elements[f2].value + 1 * valdif;
        }
        //f.elements["old" + el.name].value = price;
    }
    f.elements["old" + ElementName].value = price;
}

function conferenceFullReg(el, fullReg, price1, price2, price3) {
    var f = document.forms[0];

    var d1 = GetCheckedRadioValue(f.elements["productsafety_conf_20101026"]);
    var d2 = GetCheckedRadioValue(f.elements["productsafety_conf_20101027"]);
    var d3 = GetCheckedRadioValue(f.elements["productsafety_conf_20101028"]);

    var d1 = GetCheckedRadioValue(f.elements["safety_conf_20101026"]);
    var d2 = GetCheckedRadioValue(f.elements["safety_conf_20101027_morning"]) + GetCheckedRadioValue(f.elements["safety_conf_20101027_afternoon"]);
    var d3 = GetCheckedRadioValue(f.elements["safety_conf_20101028"]);


    var num = 0;
    if (d1 && d1 != "noSession") num++;
    if (d2 && d2 != "noSession") num++;
    if (d3 && d3 != "noSession") num++;

    var ElementName = '';
    //need to combine morning and afternoon values for Wednesday 28th
    if(el.name == 'safety_conf_20101027_morning' || el.name == 'safety_conf_20101027_afternoon'){
        ElementName = 'safety_conf_20101027';
    }
    else {
        ElementName = el.name;
    }


    if (f.elements["old" + ElementName].value == 0) {
        f.elements["SubTotal"].value = 0;
        switch (num) {
            case 1:
                f.elements["TotalPrice"].value = f.elements["TotalPrice"].value - price1;
                break;
            case 2:
                f.elements["TotalPrice"].value = f.elements["TotalPrice"].value - price2;
                break;
            case 3:
                f.elements["TotalPrice"].value = f.elements["TotalPrice"].value - price3;
                break;
        }
        updatePriceFields(el, fullReg, 'SubTotal', 'TotalPrice');
        checkDiscount(price1, price2, price3, 1);
    } else {
    updatePriceFields(el, 0, 'SubTotal', 'TotalPrice');
    checkDiscount(price1, price2, price3, -1);
        switch (num) {
            case 1:
                f.elements["SubTotal"].value = 1 * price1;
                f.elements["TotalPrice"].value = 1 * f.elements["TotalPrice"].value + price1;
                break;
            case 2:
                f.elements["SubTotal"].value = 1 * price2;
                f.elements["TotalPrice"].value = 1 * f.elements["TotalPrice"].value + price2;
                break;
            case 3:
                f.elements["SubTotal"].value = 1 * price3;
                f.elements["TotalPrice"].value = 1 * f.elements["TotalPrice"].value + price3;
                break;
        }
    }
}
// ====================
// Function:    checkDiscount
//
// Purpose:     Custom function to check discount value if 2 or 3 products has been selected 
//
// Input:       
//          -   price1 - price for 1 product, 
//          -   price2 - combined price of 2 products,
//          -   price3 - combined price of 3 products,
//          -   direction = 1 or -1 for adding/removing price
//
// Output:      Alters values of two "hard coded" "summary" fields
//
// Assumptions:
//          -   There is only one form on the page
//
// History:     20080815 GR created
// ====================
function checkDiscount(price1, price2, price3, direction) {
    if ( price1 && price2 && price3 ) {
	    var f = document.forms[0];

	    var d1 = GetCheckedRadioValue(f.elements["productsafety_conf_20101026"]);
	    var d2 = GetCheckedRadioValue(f.elements["productsafety_conf_20101027"]);
	    var d3 = GetCheckedRadioValue(f.elements["productsafety_conf_20101028"]);

	    var d1 = GetCheckedRadioValue(f.elements["safety_conf_20101026"]);
	    var d2 = GetCheckedRadioValue(f.elements["safety_conf_20101027_morning"]) + GetCheckedRadioValue(f.elements["safety_conf_20101027_afternoon"]);
	    var d3 = GetCheckedRadioValue(f.elements["safety_conf_20101028"]);

	    
	    var num = 0;
	    if (d1 && d1 != "noSession") num++;
	    if (d2 && d2 != "noSession") num++;
	    if (d3 && d3 != "noSession") num++;
	    
	    //alert("num=" + num + " previous count=" + f.elements['confcount'].value + " direction=" + direction);
	    if ( num != f.elements['confcount'].value && f.elements["oldsafety_conf_FullReg"].value == 0) {
	        // we don't want to update discounts if "the same" feature has been clicked again
	        if (num == 3 && direction == 1) {
                f.elements['SubTotal'].value = 1 * f.elements['SubTotal'].value - (1 * price2 + 1 * price1 - 1 * price3);
                f.elements['TotalPrice'].value = 1 * f.elements['TotalPrice'].value - (1 * price2 + 1 * price1 - 1 * price3);
	        } else if ( num == 2 ) {
	            if ( direction == 1 ) {
	                f.elements['SubTotal'].value = 1*f.elements['SubTotal'].value - (2*price1 - 1*price2);
	                f.elements['TotalPrice'].value = 1*f.elements['TotalPrice'].value - (2*price1 - 1*price2);
	            } else {
	                f.elements['SubTotal'].value = 1*f.elements['SubTotal'].value + (1*price2 + 1*price1 - 1*price3);
	                f.elements['TotalPrice'].value = 1*f.elements['TotalPrice'].value + (1*price2 + 1*price1 - 1*price3);
	            }
	        } else if ( num == 1 && direction == -1 ) {
	            f.elements['SubTotal'].value = 1*f.elements['SubTotal'].value + (2*price1 - 1*price2);
	            f.elements['TotalPrice'].value = 1*f.elements['TotalPrice'].value + (2*price1 - 1*price2);
	        }
	    }
	    f.elements['confcount'].value = num;
	    //alert(f.elements['confcount'].value);
	}
}



function checkDayTwoSessions(el, price1, price2, price3){
    var f = document.forms[0];
    
    if(el.name == 'productsafety_conf_20101027_morning'){
        //check whether an amount has already been added to oldproductsafety_conf_20101027
        if(f.elements['oldproductsafety_conf_20101027'].value == '0'){
            f.elements['oldproductsafety_conf_20101027'].value = price1;
        }
        //check whether an afternoon session has been selected
        if(GetCheckedRadioValue('productsafety_conf_20101027_afternoon') == ''){
            document.getElementById('CheckSessionAlsoSelected').innerHTML = 'Please also select an afternoon session';
            document.getElementById('CheckSessionAlsoSelected').style.display = 'block';
        }
        else {
            document.getElementById('CheckSessionAlsoSelected').style.display = 'none';
        }
    }
    else {
        //afternoon has been ticked
         //check whether an amount has already been added to oldproductsafety_conf_20101027
        if(f.elements['oldproductsafety_conf_20101027'].value == '0'){
            f.elements['oldproductsafety_conf_20101027'].value = price1;
        }
        //check whether a morning session has been selected
        if(GetCheckedRadioValue('productsafety_conf_20101027_morning') == '0'){
            document.getElementById('CheckSessionAlsoSelected').innerHTML = 'Please also select a morning session';
            document.getElementById('CheckSessionAlsoSelected').style.display = 'block';
        }
        else {
            document.getElementById('CheckSessionAlsoSelected').style.display = 'none';
        }
    }
    
    //uncheck the 'no session' radio button
    document.getElementById('safety_conf_20101027g').removeAttribute('checked');
    
    checkDiscount(price1,price2,price3,1);
}




function checkSessionAlsoSelected(sessiontime){
    var radioname;
    var sessionname;
    switch(sessiontime){
        case 'morning':
            //morning radio group
            radioname = 'safety_conf_20101027_morning';
            sessionname = ' morning ';
            break;
        case 'afternoon':
            //afternoon radio group
            radioname = 'safety_conf_20101027_afternoon';
            sessionname = 'n afternoon ';
            break;
        }
    var f = document.forms[0];
    if(GetCheckedRadioValue(f.elements[radioname]).length == '0'){
        document.getElementById('CheckSessionAlsoSelected').appendChild(document.createTextNode('Please ensure you also select a' + sessionname + 'session'));
        document.getElementById('CheckSessionAlsoSelected').style.display = 'block';
    } 
    else {
        document.getElementById('CheckSessionAlsoSelected').style.display = 'none';
    }
}



// ====================
// Function:    GetCheckedRadioValue
//
// Purpose:     To get value of radio boxes fild(s)
//
// Input:       
//          -   radioObj - object holding (array of) radio, 
//
// Output:      Current field value or ""
//
// History:     20080815 GR transferred from admin JS
// ====================
function GetCheckedRadioValue(radioObj)  {
	if ( !radioObj ) {
		return "";
	}
	var radioLength = radioObj.length;
	if( radioLength == undefined ) {
		if ( radioObj.checked ) {
			return radioObj.value;
		} else {
			return "";
		}
	}
	for ( var i = 0; i < radioLength; i++ ) {
		if ( radioObj[i].checked ) {
			return radioObj[i].value;
		}
	}
	return "";
}

function GetCheckedCheckboxValue(checkboxObj) {
    if (!checkboxObj) {
        return "";
    }
    if (checkboxObj.checked) {
        return checkboxObj.value;
        } else {
            return "";
        }
    //return "";
}

