
	// If site_url was not set externally via the header html - use the js variable (rtather than the php variable)
   if (typeof SITE_URL == "undefined") SITE_URL = 'http://'+ document.location.host + '/';

	// ------------------------------------------------------------------------

	/**
	* General all purpose scripts for each page
	*/

		/*
	   *	Used on main search boxes in the interface
	   */
		function focusSearchBox(box) {
			if (box.defaultText==undefined) {
				box.defaultText = box.value;
			}
			if (box.defaultText == box.value) box.value = '';
		}

		function blurSearchBox(box) {
			if (box.defaultText!=undefined && box.value=='') {
			box.value = box.defaultText;
			}
		}

		/*
		 * Old style use to open a popup page
		 */

		function openwin(newUrl, w, h) {
			if (window.name != 'Window') {
				if (w==undefined) w = 700;
				if (h==undefined) h = 400;
				window.open(newUrl,'Window',config='toolbar=no,location=no,directories=no,status=yes,menubar=yes,width='+w+',height='+h+',left=50,top=50,scrollbars=yes,resizable=yes');
			} else {
				//If already open - just change location (like for printer friendly of popups
				if (location.href.indexOf('spectronicsinoz') > 0) rootPath = "www.spectronicsinoz.com";
				else rootPath = "marketing";
				location = 'http://' + rootPath + '/' + newUrl;
			}
		}

		// Simple function to open a popup (used through catalogue and articles)
		function popup() {
			var a = popup.arguments;
			switch (a.length) {
			   // A url with an anchor
				case 2:
					var anchor = (a.length > 1) ? '#'+a[1] : '';
					openwin('/product/'+ a[0] + '/popup' + anchor);
					break;
				// Open winwith custom x, y co-ordinates
				case 3:
					openwin('/product/'+ a[0] + '/popup', a[1], a[2]);
					break;
				// A normal popup url
				default:
				   openwin('/product/'+ a[0] + '/popup');
			}
		}

      // Simple function to open a popup (used through catalogue and articles) - though in a different style
		function popupMinimal() {
			var a = popup.arguments;
			switch (a.length) {
			   // A url with an anchor
				case 2:
					var anchor = (a.length > 1) ? '#'+a[1] : '';
					openwin('/product/'+ a[0] + '/none/' + anchor);
					break;
				// Open winwith custom x, y co-ordinates
				case 3:
					openwin('/product/'+ a[0] + '/none', a[1], a[2]);
					break;
				// A normal popup url
				default:
				   openwin('/product/'+ a[0] + '/none');
			}
		}


		/*
		 * Goes to the log out url - sending the current page as a return url
		 */
		function staffLogout()
		{
		   var url = "http://" + location.host + "/?path=/staff/logout&return="+ this.location.href.replace("http://" + location.host + "/", "");
		   location=url;
		}



		/*
		 * Main document ready call for use on all pages
		 */
      $(document).ready(function() {


         // Fix #links named links which don't work with our easy urls
         jQuery("a").each(function() {
            var url = jQuery(this).attr('href');
            if (url!=undefined)
            {
	            if (url.indexOf('#')==0)
	            {
						url = CURRENT_URL + url;
	               jQuery(this).attr({ href: url });
	            }
				}
         });


			// Show external links with an icon
			jQuery('a').each(function () {
				var href = jQuery(this).attr('href');
				if (href==undefined) return;

				// If has 'http' and doesn' thave SITE_URL (set via header.php) - show the external image
				// External links
				if (href.indexOf('http')==0 && href.indexOf(SITE_URL)==-1 && jQuery(this).attr('class').indexOf('no-external-icon')==-1)
				{
				   // Don't add it if there's already an image in th elink (cause it will look crumy)
				   var images = $(this).find("img");
				   if (images.length==0)
				   {
			   		$(this).append(' <img style="margin:0;padding:0;float:none;display:inline;" src="/topsight/website/assets/images/external-link.gif" alt="This is an external link" />');
			  	 	}
				}
				// Internal links
				else
				{
					// This is an internal image - make sure it prevserves the 'popup' display if we're showing that
	            if (CURRENT_DISPLAY_MODE=='popup')
	            {
	               // Dont' do this for valid files to download
	               // Don't do this if popup is already in the link href
	               // Don't do thus for staff links (which are often in popups)
	               // Don't do this if target has been set for ita
	               if (
	                  (href.indexOf('.pdf')==-1 && href.indexOf('.doc')==-1 && href.indexOf('.zip')==-1 && href.indexOf('.jpg')==-1 && href.indexOf('.jpeg')==-1 && href.indexOf('.gif')==-1) &&
                     href.indexOf('/popup')==-1 &&
                     href.indexOf('/staff')==-1 &&
                     jQuery(this).attr('target')=='')
	               {
                     // Put popup within the url - either replacing a # symbol - or just at the end of the url
                     if (href.indexOf('#')==-1 && href.indexOf('/staff') > -1)
                     {
                        $(this).attr({'href':href+'/popup'});
                     }
                     else
                     {
                     	jQuery(this).attr({'href':href.replace('#', '/popup#')});
                     }
                  }
	            }

				}
			});


         // Make items with class 'glow' fade from yellow
         jQuery(".glow").each(function() {
            var bgcolor = $(this).css('background-color');
            $(this).css({'background-color':'#FFFFE0'});
				$(this).animate({
					backgroundColor: bgcolor
				}, 2400 );
         });

         jQuery(".glowgreen").each(function() {
            var bgcolor = $(this).css('background-color');
            $(this).css({'background-color':'#F1FFDB'});
				$(this).animate({
					backgroundColor: bgcolor
				}, 2400 );
         });

			/*
			 * Handles the automatic selecting of checkboxes for each input field in the advanced search
			 */
			if ($("#advancedSearchTable"))
			{
			   // The function to select the checkbox representing the input field
			   var selectTheCheckbox = function () {
	               var rowCells = $(this).parent().parent().children()
	               var firstCell = $(rowCells[0]);
	               var firstCellChildren = firstCell.children();
	               var checkbox = $(firstCellChildren[0]);
	            	checkbox.attr({ checked: true });
					}

			   // Select it on keypress for text fields
	         $("#advancedSearchTable .textinput").each(function() {
	            $(this).keydown(selectTheCheckbox);
	         });

	         // And on click for dropdowns
	         $("#advancedSearchTable .dropdown").each(function() {
	            $(this).click(selectTheCheckbox);
	         });
			}


      });


	// ------------------------------------------------------------------------

	/**
	* Product page scripts
	*/

      $(document).ready(function() {

         // Clicking product img toggles the checkbox (and the image src)
			jQuery(".add img").click(function () {
			   var input = $(this).next();
			   var checked = input.attr('checked');
			   input.attr({ checked: !checked });
			   setAddShoppingImg($(this).next(), $(this));
			});

			// This checks the page and sets the checked image (for when they hit back etc
			jQuery(".add img").each(function () {
            setAddShoppingImg($(this).next(), $(this));
			});

			// Clicking the product checkbox toggles the img src
			jQuery(".add input").click(function () {
            setAddShoppingImg($(this), $(this).prev());
			});

      });

		// Get the 'checked' attribute and set
		function setAddShoppingImg(input, img) {
		   var checked = $(input).attr('checked');
			var src = $(img).attr('src');
			src = src.replace('_on.gif', '.gif');
			src = (!checked) ? src.replace('_on.gif', '.gif') : src.replace('.gif', '_on.gif');
         $(img).attr({ src: src });
		}

		/*
		 * Called by the add button to select all items
		 */
		function selectAllProductItems(submitAfter)
		{
		   $(".add input").each(function () {
		      //var checked = $(this).attr('checked');
            $(this).attr({ checked: true });
            setAddShoppingImg($(this), $(this).prev());
			});
			if (submitAfter) addSelectedProductItemsToList();
		}

		/*
		 * Submits
		 */
		function addSelectedProductItemsToList()
		{
			var hasSelectedItems = false;
			$(".add input").each(function ()
			{
			   var checked = $(this).attr('checked');
			   if (checked)
			   {
			      hasSelectedItems = true;
			   }
			});
			if (hasSelectedItems)
			{
			   $("#productlistForm").submit();
			}
			else
			{
			   $("#addErrorMessage span").text("Please tick the ckeckbox next to the item(s) you wish to add to your list").show().fadeTo(5000, 1).fadeOut(3000);
			}
		}

	// ------------------------------------------------------------------------

	/**
	* Online order scripts
	*/

		/*
		 * Attach click events to each "fill" link on the form
		 */

		$(document).ready(function() {
		   var orderAutoFillFields = ['title', 'fname', 'lname', 'email', 'cemail', 'phone', 'orgname', 'fax', 'address1', 'address2', 'address3', 'postcode', 'country'];
		   jQuery("#fillBillFromContactDetails").click(function (e) {
            e.preventDefault();
		      autoFillFields(orderAutoFillFields, '', 'bill_');
			});
			$("#fillShipFromContactDetails").click(function (e) {
			   e.preventDefault();
		      autoFillFields(orderAutoFillFields, '', 'ship_');
			});
			jQuery("#fillShipFromBillDetails").click(function (e) {
            e.preventDefault();
		      autoFillFields(orderAutoFillFields, 'bill_', 'ship_');
			});
		});

		function autoFillFields(fields, fromFieldKey, toFieldKey) {
		   jQuery.each(fields, function() {
		      var fromField 	= $("#id_" + fromFieldKey + this);
		      var toField 	= $("#id_" + toFieldKey   + this);

		      if ( $(fromField) && $(toField) && typeof(fromField.attr('name')) != "undefined"  && typeof(toField.attr('name')) != "undefined") {
		         toField.attr({value:fromField.attr('value')})
		      }
		    });
		}


	// ------------------------------------------------------------------------

	/**
	* Search function to browse below items
	*/

	$(document).ready(function() {
	   jQuery(".itemBrowseBelow").each(function () {

		});

		initBrowseBelowButtons();
	});

	function initBrowseBelowButtons()
	{
	   jQuery(".addItemLink").click(function () {

	      if ($(this).attr('isLoading')=='Y')
			{
			   return;
			}
         $(this).attr({'isLoading': 'Y'});

	   	var id = $(this).attr('id')
	   	id = id.replace('addItemLink', '');
	      var elem = $(this);

	      elem.text('One moment...');

			$.get("/shoppinglist/add/"+id, { name: "John", time: "2pm" },
				function(data){
				   elem.parent().fadeTo(200, 0, function()
						{
						   elem.parent().fadeTo(200, 1);
							elem.replaceWith('<span class="addItemLinkDone glowgreen">This item has been added to <a href="/shoppinglist">your shopping list</a></span>');
						}
					);

					// Add this label if it's not there already (ie their first item)
	      		if ($("#shoppingListCountLabel").id==undefined)
					{
					   $(".menuShoppinglist a").append('<span id="shoppingListCountLabel"></span>');
					}

					$("#shoppingListCountLabel").text(data);

				}
			);
	   });

	   jQuery(".itemBrowseBelow").each(function () {

			// Make sure we don't add the event listeners to the same object again
			if ($(this).attr('hasMyEvents')=='Y')
			{
			   return;
			}
         $(this).attr({'hasMyEvents': 'Y'});

         // Add the event listeners
			$(this).click(function () {

            if ($(this).attr('isLoading')=='dfY')
				{
				   
					$(this).text('I know already!');
				   return;
				}


				// Get main variables
			   var id = $(this).attr('id');
	         id = id.replace('listItem', '');

	         var tagId = 'itemBelow'+ id;
	         id = id.substr(0, id.indexOf('_')); // Remove the key part at the end

            var parentContainer = $(this).parent();
            var linkItem = $(this);

            // This is called when we're toggling the search results
			   if ($('#'+ tagId).attr('id')!=undefined)
				{
				   $('#'+ tagId).toggle();
					var display = $('#'+ tagId).css('display');

					if (display=='none') $(this).text('Show item\'s below this item');
					else $(this).text('Hide item\'s below this item');

				   var src = 'url(/topsight/website/assets/images/'+ ((display=='none') ? 'expand.gif' : 'collapse.gif') + ')';
				   $(this).css({'background-image': src});
					return;
			   }

				$(this).css({'background-image': 'url(/topsight/website/assets/images/loading-tiny.gif)'});
				$(this).css({'padding-left': '22px'});
				$(this).text('One moment...');


				$(this).attr({'isLoading': 'Y'});

	         $.post("/search_lookbelow/"+id, { isRowOne: parentContainer.hasClass('row1'), current_url: CURRENT_URL },
					function(data){
					   linkItem.css({'padding-left': '18px'});
					   if (data!='' && data.indexOf('<!--OK-->')>=0)
					   {
					      linkItem.text('Hide item\'s below this item');
					   	parentContainer.append('<div id="'+ tagId +'" class="nestedItems">'+ data +'</div>');
					   	linkItem.css({'background-image': 'url(/topsight/website/assets/images/collapse.gif)'});
							initBrowseBelowButtons();  // Re-init the buttons because they'll need it when they're dynamically loaded
						}
						else if (data.indexOf('<!--NO CHILDREN-->')>=0)
						{
						   linkItem.replaceWith('<span style="font-size:11px;" class="asdfasdf">There are no items below this item</span>');
						   parentContainer.find(".asdfasdf").fadeTo(2000, 0);
						}
						else
						{
						   linkItem.replaceWith('<span style="font-size:11px;">Ths items below this item could not be loaded</span>');
						}
					}
				);

			})
      });
	}
	// ------------------------------------------------------------------------

	/**
	* print functionality for any page
	*/

	$(document).ready(function() {
     if (location.href.indexOf("print-this-page") >= 0)
     {
        window.print();
     }
	});

	// ------------------------------------------------------------------------

	/**
	* Conference registration scripts
	*/

		/*
		 * Attach click events to each "fill" link on the form
		 */

		$(document).ready(function() {
		   var registerAutoFillFields = ['title', 'firstname', 'surname', 'address1', 'address2', 'address3', 'suburb', 'state', 'other_state', 'postcode', 'country', 'email', 'mobile', 'phone'];
         
         
         jQuery("#fillInvoiceFromPersonalDetails").click(function () {
		      autoFillFields(registerAutoFillFields, '', 'invoice_');
			});

         jQuery("#fillInvoiceFromOrgDetails").click(function () {
		      autoFillFields(registerAutoFillFields, 'org_', 'invoice_');
			});
			
         jQuery("#fillOrgFromPersonalDetails").click(function () {
		      autoFillFields(registerAutoFillFields, '', 'org_');
			});

			$('#id_org_not_applicable').click(function(){
			  check_org_applicable_field();
			});
			
			// ---- extra call is done for things like a page being submitted
			if ( $("#id_org_not_applicable").length > 0 ) {
   			check_org_applicable_field();
   		}
   		
   		if ( $("#id_home_preferable").length > 0 ) {
			   check_home_preferred_mailing_field();
			}
			
			$('#id_home_preferable').click(function(){
            check_home_preferred_mailing_field();
			});
		});

   function check_home_preferred_mailing_field()
   {
	   if ($('#id_home_preferable').is(':checked'))
	   {
	      enable_home_fields();
	   } else {
         disable_home_fields();
         if ($('#id_org_not_applicable').is(':checked'))
         {
            $('#id_org_not_applicable').attr("checked", false);
            check_org_applicable_field();
         }
	   }
   }

   function check_org_applicable_field()
   {
      if ($('#id_org_not_applicable').is(':checked'))
		{
	      disable_field('id_organisation', 'Organisation');
	      disable_field('id_organisation_2', 'Organisation 2');
	      disable_field('id_org_address1', 'Address 1');
	      disable_field('id_org_address2', 'Address 2');
	      disable_field('id_org_address3', 'Address 3');
	      disable_field('id_org_suburb', 'Suburb');
	      disable_field('id_org_state', 'State');
	      disable_field('id_org_other_state', 'Other');
	      disable_field('id_org_postcode', 'Postcode');
	      disable_field('id_org_country', 'Country');
	      disable_field('id_org_timezones', 'Timezone');
	      disable_field('id_org_phone', 'Phone (Daytime)');
	      disable_field('id_org_mobile', 'Mobile');
	      disable_field('id_org_fax', 'Fax');
	      //disable_field('id_org_email', 'Email');
	      //disable_field('id_org_confirm_email', 'Confirm Email');
	      $('#id_home_preferable').attr("checked", true);
	      enable_home_fields();
		} else {
         enable_field('id_organisation', 'Organisation <span title="This field is required">*</span>');
         enable_field('id_organisation_2', 'Organisation 2');
         enable_field('id_org_address1', 'Address 1 <span title="This field is required">*</span>');
         enable_field('id_org_address2', 'Address 2');
         enable_field('id_org_address3', 'Address 3');
         enable_field('id_org_suburb', 'Suburb <span title="This field is required">*</span>');
         enable_field('id_org_state', 'State <span title="This field is required">*</span>');
         enable_field('id_org_other_state', 'Other <span title="This field is required">*</span>');
         enable_field('id_org_postcode', 'Postcode <span title="This field is required">*</span>');
         enable_field('id_org_country', 'Country <span title="This field is required">*</span>');
         enable_field('id_org_timezones', 'Timezone <span title="This field is required">*</span>');
         enable_field('id_org_phone', 'Phone (Daytime) <span title="This field is required">*</span>');
         enable_field('id_org_mobile', 'Mobile');
         enable_field('id_org_fax', 'Fax');
         //enable_field('id_org_email', 'Email <span title="This field is required">*</span>');
         //enable_field('id_org_confirm_email', 'Confirm Email <span title="This field is required">*</span>');
      }
   }

   function enable_home_fields()
   {
      enable_field('id_address1', 'Address 1 <span title="This field is required">*</span>');
      enable_field('id_address2', 'Address 2');
      enable_field('id_address3', 'Address 3');
      enable_field('id_suburb', 'Suburb <span title="This field is required">*</span>');
      enable_field('id_state', 'State <span title="This field is required">*</span>');
      enable_field('id_other_state', 'Other <span title="This field is required">*</span>');
      enable_field('id_postcode', 'Postcode <span title="This field is required">*</span>');
      enable_field('id_country', 'Country <span title="This field is required">*</span>');
      enable_field('id_timezones', 'Timezones <span title="This field is required">*</span>');
      enable_field('id_phone', 'Phone (Daytime) <span title="This field is required">*</span>');
      
   }
   
   function disable_home_fields()
   {
      disable_field('id_address1', 'Address 1');
      disable_field('id_address2', 'Address 2');
      disable_field('id_address3', 'Address 3');
      disable_field('id_suburb', 'Suburb');
      disable_field('id_state', 'State');
      disable_field('id_other_state', 'Other');
      disable_field('id_postcode', 'Postcode');
      disable_field('id_country', 'Country');
      disable_field('id_timezones', 'Timezone');
      disable_field('id_phone', 'Phone (Daytime)');
      disable_field('id_home_phone', 'Phone');
   }

   function enable_field(field, label)
   {
      $('#'+field).removeAttr("disabled");
      $('label[for="'+field+'"]').html(label);
      if ($('#'+field).parent().hasClass('error'))
      {
         $('#'+field).css('border-color', '#f96363');
      }
      $('#'+field).css('background-color', '#FFFFFF');
   }
   
   
   function disable_field(field, label)
   {

      $('#'+field).attr("disabled", true);
      $('label[for="'+field+'"]').html(label);
      $('#'+field).css('background-color', '#f4f4f4');
      $('#'+field).css('border-color', '#D4E3E2');
      $('#'+field).parent().removeClass('error');
   }

	// ------------------------------------------------------------------------

	/**
	* Homepage carousel registration scripts
	*/

   $(document).ready(
		function(){
         if (typeof(SHOW_IMAGE_CAROUSEL) != "undefined")
         {
   			$('#fade').innerfade({
   				speed: 'slow',
   				timeout: 4000,
   				type: 'sequence',
   				containerheight: '390px'
   			});
   		}
	});



// ------------------------------------------------------------------------

	/**
	* Conference: register form radio button functionality
	*/
  var $session_selection = '';
    $(document).ready(
		function(){
		   if (jQuery("#regcomplete").length > 0)
		   {
		      $session_selection = $("#session_selection");

            // check if the regcustom checkbox is checked on load and if so, set the css
		      if ($('#regcustom').is(':checked'))
		      {
               untick_preconference();
               set_custom_option_box_css();
		      }

		      // check if the regcustom checkbox is checked on load and if so, set the css
		      if ($('#id_P').is(':checked'))
		      {
               _load_timetable_choices();
		      }

		      // ---- complete registration
      		$("#regcomplete").click(function(){
               $("#option1regbox").addClass("regtypeSelected");
               $("#option2regbox").removeClass("regtypeSelected");
               $("#id_P, #id_D1, #id_D2, #id_D3, #id_ALL, #id_M").attr("checked","");

               _load_timetable_choices();
      		});

          // ---- custom registration
          $("#regcustom").click(function(){
               untick_preconference();
               set_custom_option_box_css();
               _load_timetable_choices();
      		});

      		$("#id_D1, #id_D2, #id_D3").click(function(){
               untick_preconference();
               $("#id_ALL").attr("checked","");
               select_custom_option_box();
      		});

      		$("#id_ALL").click(function(){
               untick_preconference();
      		   $("#id_D1, #id_D2, #id_D3").attr("checked","");
               select_custom_option_box();
      		});

      		$("#id_P, #id_ALL, #id_M").click(function(){
               untick_preconference();
               if ($(this).attr('id') == 'id_P')
               {
                  _load_timetable_choices();
               }
               select_custom_option_box();
      		});
      	}
	});

   function untick_preconference()
   {
      $("#P1, #P2, #P3, #P4, #P5, #P6, #P7").attr("checked","");
      pre_selection = '';
   }
   
	function select_custom_option_box()
	{
	    _load_timetable_choices();
      $("#regcustom").attr("checked","checked");
      $("#regcomplete").attr("checked","");
      set_custom_option_box_css();
	}

	function set_custom_option_box_css()
	{
      $("#option1regbox").removeClass("regtypeSelected");
      $("#option2regbox").addClass("regtypeSelected");
	}
	
	
// ------------------------------------------------------------------------

	/**
	* Advanced search results
	*/	
	function process_click()
	{
	   self.name = "searchresults";
      document.getElementById("exportForm").action = document.getElementById("area").options[document.getElementById("area").selectedIndex].value;
      if (document.getElementById("area").selectedIndex > 0)
      {
         document.getElementById("exportForm").target = '_new';
         document.getElementById("exportForm").submit();
      } else {
         url = '/topsight/cms/load/search/'+document.getElementById("cat").value;
         var myWin = window.open(url,'cms');
      }
      
	}
	

// ------------------------------------------------------------------------

	/**
	* EOI Form - Prevent cut and paste of email addresses into the confirm field.
	*/	
	   $(document).ready(
      function(){
         if (typeof(isLoggedIn) === 'undefined')
         {
            // check for cut and paste in input fields
            $("input").focus(function () {
               attribute = $(this).attr('nopaste');

               if (typeof(attribute) != 'undefined')
               {
                  $(this).bind('cut copy paste', function(e) {
                  	e.preventDefault();
                  });
               }

     		  });

     		  // check for cut and paste in text areas
     		  $("textarea").focus(function () {
               attribute = $(this).attr('nopaste');

               if (typeof(attribute) != 'undefined')
               {
                  $(this).bind('cut copy paste', function(e) {
                  	e.preventDefault();
                  });
               }

     		  });
       }
   });

// ------------------------------------------------------------------------

	/**
	* Cooliris Object
	*/	
   
   $(document).ready(
		function(){
		   // check if the flashobject div exists
		   if (jQuery("#flashobject").length > 0)
		   {
		      // check if we passed in a # 
		      var location = document.location.toString();
		      
		      if (location.match('#'))
		      {
   		      var anchor = location.split('#')[1];
               load_cool_iris('http://www.spectronicsinoz.com/cooliris/Rest of the World');
		      } else {
               load_cool_iris('http://www.spectronicsinoz.com/cooliris');
            }
		   
		     	$('#cooliris-selector a').live('click',function(){
		     	  $("#flashobject").html(''); // clears the div so multiple swf objects aren't appended
         		$('#cooliris-selector span.thumb a').removeClass('active');
         		$(this).addClass('active').addClass('visited');
         		var $href = $(this).attr('href');
               load_cool_iris($href);
         		return false;
         	});

      	}
	});
	
	function load_cool_iris(href)
	{
	  $('#flashobject').flash({  
         swf: 'http://apps.cooliris.com/embed/cooliris.swf', 
         width: 760,
         height:450,
         wmode: 'transparent', // allows menus to appear over the cooliris wall
         flashvars: {  
          style: 'white',
            feed: href  
         } 
      }); 
	}
	
// ------------------------------------------------------------------------

	/**
	* RSS Video Guides
	*/	
   
   $(document).ready(
		function(){
		   // check if the flashobject div exists
		   if (jQuery("#firefox3-guide").length > 0)
		   {
             load_guide('firefox3-guide', 'Firefox3_RSS_Feed/Firefox3_RSS_Feed.swf');
      	} 
      	
      	if (jQuery("#google-guide").length > 0)
		   {
             load_guide('google-guide', 'Google_Reader/Google_Reader.swf');
      	}
         
         if (jQuery("#ie8-guide").length > 0)
		   {
             load_guide('ie8-guide', 'IE8_RSS_Feed/IE8_RSS_Feed.swf');
      	} 
	});
	
	function load_guide(div, url)
	{
		var so = new SWFObject('/topsight/website/assets/swf/guides/'+url, "Captivate", "791", "413", "9", "#CCCCCC");
		so.addParam("quality", "high");
		so.addParam("name", "Captivate");
		so.addParam("id", "Captivate");
		so.addParam("wmode", "opaque");
		so.addParam("bgcolor","#ffffff");
		so.addParam("menu", "false");
		so.setAttribute("redirectUrl", "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash");
		so.write(div);
		
		
	/*
		var so = new SWFObject('/topsight/website/assets/swf/guides/'+url, "Captivate", "708", "370", "9", "#FFFFFF");
   	so.addParam("wmode", "opaque");
   	so.addParam("menu", "false");
      so.setAttribute("redirectUrl", "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash");
      so.addParam("quality", "high");
   	so.write(div);*/
	}
	
// ------------------------------------------------------------------------

	/**
	* Workshop Registration forms
	*/

   $(document).ready(
		function(){
		   if (jQuery("#id_preferred_workshop").length > 0 || jQuery("#id_preferred_workshop_alt").length > 0)
		   {
            // find what type of form this is
            var rego = _find_rego();
            $('ul.checkboxes input').click(function()
            {
               if ($(this).is(':checked') && $(this).attr('name') == "preferred_workshop[]")
               {
                  _set_matrix_rego_checkboxes(this, rego);
               }
            });
      	} 
	});

   // ------------------------------------------------------------------------

	/**
	 * Works on a matrix of checkboxes. Good examples are:
	 * 
	 * http://localhost/register/workshop/hamiltonnov09form
	 * http://localhost/register/workshop/centralqldworkshopsform        	 
	 * 	 
	 * @author  Adrian Diente
	 * @created  26/08/2009 9:09:41 AM
	 * 
	 * @access 	public
	 * @param	object string
	 * @return	unset
	 */
   function _set_matrix_rego_checkboxes(object, rego)
   {
      var checkbox_per_col = 0;
      var checkbox_label = 'id_preferred_workshop';
      var affect_only_current_row =false;
   
      switch(rego)
      {
         case 'dynavoxworkshopswaform':  affect_only_current_row = true; checkbox_per_col = 3; total_checkboxes = 3; break;
         case 'waggawaggaworkshopform':  affect_only_current_row = true; checkbox_per_col = 4; total_checkboxes = 4; break;
         case 'centralqldworkshopsform': affect_only_current_row = false; checkbox_per_col = 4; total_checkboxes = 12; break;
         case 'hamiltonnov09form':       affect_only_current_row = true; checkbox_per_col = 4; total_checkboxes = 8; break;
         case 'singaporeoct21':       		affect_only_current_row = true; checkbox_per_col = 4; total_checkboxes = 4; break;
         case 'wellingtonoct09form':      affect_only_current_row = true; checkbox_per_col = 4; total_checkboxes = 4;break;
      }
      
      if (affect_only_current_row)
      {
	      // determine which are the end checkboxes
	      data = new Array();
	      data['affect_only_current_row'] = affect_only_current_row;
	      data['current_object_id'] = $(object).attr('id');
	      data['checkbox_label'] = checkbox_label;

	      data['checkbox_per_col'] = checkbox_per_col;
	      data['total_checkboxes'] = total_checkboxes;

	      data['start_end_checkboxes'] = _build_end_checkbox_array(data);
	      _uncheck_checkboxes(data);
		}
      
      
   }


   // ------------------------------------------------------------------------

	/**
	 * Dyamically determine which checkboxes this current_object_id affects
	 * 	 
	 * @author  Adrian Diente
	 * @created  25/08/2009 11:32:01 AM
	 * 
	 * @access 	public
	 * @param	boolean string string array integer
	 * @return	array
	 */
   function _uncheck_checkboxes(data)
   {
      data['start_end_checkboxes'] = _find_start_and_end_checkbox(data);
      
      // if we clicked on the end checkbox of the row
      if (data['affect_only_current_row'])
      {
         // if we click on one of the non-end checkboxes, untick the end checkbox for that row
         if (data['current_object_id'] != data['start_end_checkboxes'][1])
         {
            $('#'+data['start_end_checkboxes'][1]).attr("checked", "");
         } else {
            _toggle_checkbox(data);
         }
      } else {
         _toggle_checkbox(data);
      }
      
   }

   // ------------------------------------------------------------------------

	/**
	 * Dyamically checks and unchecks the checkboxes depending if we affect the current
	 * row only	 
	 * 	 
	 * @author  Adrian Diente
	 * @created  25/08/2009 4:47:24 PM
	 * 
	 * @access 	public
	 * @param	array
	 * @return	array
	 */
   function _toggle_checkbox(data)
   {
      var checkboxids = data['total_checkboxes'] - 2;
      var counter = 0;
      var first_run = true;
      var alter_checkbox = (!data['affect_only_current_row'] ? true : false);
      
      // otherwise if we click on the end checkbox, uncheck all the items in this row
      while (counter <= checkboxids)
      {
         if (first_run)
         {
            checkbox = data['checkbox_label'];
            first_run = false;
         } else {
            checkbox = data['checkbox_label']+""+counter;
            counter++;
         }
         
         // if we click on one of the end checkboxes, untick the all other checkboxes
         if ((data['current_object_id'] == data['start_end_checkboxes'][1]) && (!data['affect_only_current_row']))
         {
            if (checkbox != data['start_end_checkboxes'][1])
            {
               $('#'+checkbox).attr("checked", "");
            }
         } else {
            // check if the checkbox is the same as the first checkbox in the row
            if (checkbox == data['start_end_checkboxes'][0])
            {
               alter_checkbox = (data['affect_only_current_row'] ? true : false);
            }
            // check if the checkbox is the same as the last checkbox in the row 
            else if (checkbox == data['start_end_checkboxes'][1])
            {
               alter_checkbox = (data['affect_only_current_row'] ? false : true);
            }

            if (alter_checkbox)
            {
               $('#'+checkbox).attr("checked", "");
            }
         }
      }
   }

   // ------------------------------------------------------------------------

	/**
	 * Find the start and end checkbox that sits on this particular row
	 * 	 
	 * @author  Adrian Diente
	 * @created  25/08/2009 11:33:56 AM
	 * 
	 * @access 	public
	 * @param	string array string integer
	 * @return	array
	 */
   function _find_start_and_end_checkbox(data)
   {
      var len = data['start_end_checkboxes'].length;
      var current_id = data['current_object_id'].split(data['checkbox_label']);
         current_id = parseInt(current_id[1]);

         // check if current_id is numeric
         if (current_id != parseInt(current_id))
         {
            current_id = 0;
         }
      var end_checkbox = '';
      var start_checkbox = '';
      var counter = 0;
      data['start_end_checkboxes'] = data['start_end_checkboxes'].reverse();
      
      while(counter < len)
      {
         result = data['start_end_checkboxes'][counter].split(data['checkbox_label']);
         result = parseInt(result[1]);
         if (current_id <= result)
         {
            end_checkbox = data['checkbox_label']+""+result;
            
            temp_counter = counter - 1;
            if (temp_counter < 0)
            {
               start_checkbox = data['checkbox_label'];   
            } else {
               result = data['start_end_checkboxes'][temp_counter].split(data['checkbox_label'])
               result = parseInt(result[1]) + 1;
               start_checkbox = data['checkbox_label']+""+result;
            }
            counter = len;
         }
         
         counter++;
      }
      
      return new Array(start_checkbox, end_checkbox);
   } 
 
   // ------------------------------------------------------------------------

	/**
	 * Dyamically figure out the checkboxes at the end of each row
	 * 	 
	 * @author  Adrian Diente
	 * @created  25/08/2009 11:14:00 AM 	 
	 * 
	 * @access 	public
	 * @param	integer integer
	 * @return	array
	 */
   function _build_end_checkbox_array(data)
   {
      var temp_array = new Array();
      var rows = (data['total_checkboxes'] / data['checkbox_per_col']);
      
      // General rule is remove 2 from the total then minus total_checkboxes to determine end checkboxes
      // We remove 2 from total because the first checkbox has no number attached to the id and the 
      // 2nd checkboxes starts at zero.
      counter = 0;
      startid = data['total_checkboxes'] - 2;
      
      while (counter < rows)
      {
         // check if we've hit the first checkbox in the list
         if (startid < 0) {
            startid = '';
            counter = rows;
         }
         
         temp_array[counter] = data['checkbox_label']+""+startid;
         startid = startid - data['checkbox_per_col'];
         counter++;
      }
      
      return temp_array;
   }

	/*
	 * parses the url to return the last option
	 * 
	 * @access 	public
	 * @param	unset
	 * @return	string	 	 
	 */
   function _find_rego()
   {
      var location_str = location.href;
      location_str = location_str.split('/');
      return location_str[5];
   }
	

// ------------------------------------------------------------------------

	/**
	* Facebook Fans
	*/		
	
	$(document).ready(
		function(){
         if ((jQuery("#fbdiv").length > 0) && (typeof(FB) !='undefined'))
   	   {
            FB.init("966d7293c34a1aa387b0d63589096045");
            $('#facebook a').live('click',function (){
               _load_facebook_fans();
            });
            
            // close the div
            $('#close_facebox').live('click',function (){
             jQuery(document).trigger('close.facebox');
            });

      	} 
	});	
	

   function _load_facebook_fans()
   {
      var viewportwidth;
      var viewportheight;
      
      // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
      
      if (typeof window.innerWidth != 'undefined')
      {
         viewportwidth = window.innerWidth,
         viewportheight = window.innerHeight
      }
      
      // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
      else if (typeof document.documentElement != 'undefined'
        && typeof document.documentElement.clientWidth !=
        'undefined' && document.documentElement.clientWidth != 0)
      {
          viewportwidth = document.documentElement.clientWidth,
          viewportheight = document.documentElement.clientHeight
      }
      
      // older versions of IE
      
      else
      {
          viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
          viewportheight = document.getElementsByTagName('body')[0].clientHeight
      }

	
	   // figured 1 cols = roughly 8 pixels
	   width_padding = 200;
	   width = (viewportwidth - width_padding) / 8;
	   
	   // figured 1 row = roughly 18 pixels
      height_padding = 0;
	   height = (viewportheight - height_padding) / 18;

      div_data = '<div>';
      div_data += $('#fbdiv').html();
      div_data += '</div>'; 
      jQuery.facebox(''+div_data+'');
   }
   
   
// ------------------------------------------------------------------------

	/**
	* Funding Application form
	*/		
	$(document).ready(
		function(){
   	   if (jQuery("#id_funding_form").length > 0)
   	   {
   	      $("li.textarea.error").each(function(){
               $(this).css("background","none");
            })

      	} 
	});

// ------------------------------------------------------------------------

	/**
	* Wellington registration forms
	*/		
	$(document).ready(
		function(){
		    // wellington oct 2009
   	   if (jQuery(".checkboxes_wellington_oct_prefs").length > 0)
   	   {
   	      $("#id_preferred_workshop").click(function()
            {
               // if Monday 5th October is unticked
               if (!$("#id_preferred_workshop").attr("checked"))
               {
                  $("#id_extra_option").attr("checked", false);
                  $("#id_extra_option0").attr("checked", false);
                  $("#id_extra_option1").attr("checked", false);
                  $("#id_extra_option2").attr("checked", false);
               } else {
                  $("#id_extra_option").attr("checked", true);
               }
            });
            
            $("#id_preferred_workshop_alt2").click(function()
            {
               // if we choose all three tuesday workshops option
               if ($("#id_preferred_workshop_alt2").attr("checked"))
               {
                  $("#id_preferred_workshop_alt").attr("checked", false);
                  $("#id_preferred_workshop_alt0").attr("checked", false);
                  $("#id_preferred_workshop_alt1").attr("checked", false);
               }
            });
            
            
            $("input.checkbox").each(function(){
               $(this).click(function()
               {
                  if (($(this).attr('id') == "id_preferred_workshop_alt") ||
                  ($(this).attr('id') == "id_preferred_workshop_alt0") ||
                  ($(this).attr('id') == "id_preferred_workshop_alt1"))
                  {
                     $("#id_preferred_workshop_alt2").attr("checked", false);
                  }
               });  
               
            });
            
            _check_parent_selected('id_preferred_workshop');
      	} 
      	
      	// wellington sept 2009
      	if (jQuery(".checkboxes_wellington_sept_prefs").length > 0)
   	   {
   	      // Disabled
   	      return;
   	      _check_wellington_sept_set('');
   	      $("#id_preferred_workshop0").click(function()
            {
               _check_wellington_sept_set('clicked');   
            });
            
            _check_parent_selected('id_preferred_workshop0');
      	} 
	});

function _check_wellington_sept_set(action)
{
   // if Tuesday 22nd Septober is unticked
   if (!$("#id_preferred_workshop0").attr("checked"))
   {
      $("#id_extra_option").attr("checked", false);
      $("#id_extra_option0").attr("checked", false);
      $("#id_extra_option1").attr("checked", false);
      $("#id_extra_option2").attr("checked", false);
   } else {
      if (action == 'clicked')
      {
         $("#id_extra_option").attr("checked", true);
      }
   }
}

// ------------------------------------------------------------------------

/**
* checks if the parent checkbox/radio button is ticked before allowing a child
* radio button to be selected
* 
* @author  Adrian Diente
* @created  11/08/2009 2:39:17 PM
*       	
* @access  public
* @param   string
* @return  unset
*/
function _check_parent_selected(parent)
{
   $("input.radio").each(function(){
      $(this).click(function()
      {
         if (($(this).attr('id') == "id_extra_option") ||
         ($(this).attr('id') == "id_extra_option0") ||
         ($(this).attr('id') == "id_extra_option1") ||
         ($(this).attr('id') == "id_extra_option2"))
         {
            if (!$("#"+parent).attr("checked"))
            {
               $(this).attr('checked', false);
            }
         }
      });  
      
   });
}


// ------------------------------------------------------------------------

/**
* Conference Timetable generation
*/
$(document).ready(
		function(){
		
   	   if (jQuery("#session_selection").length > 0)
   	   {
   	      _load_timetable_choices();
       } 
	});

var pre_selection = '';
/*
 ensures that only 1 pre-conference is selected
*/

function check_selections(checkbox)
{
  if ($(checkbox).is(":checked"))
  {
    if (pre_selection && pre_selection != $(checkbox).val())
    {
      $(checkbox).attr("checked", false);
      alert('You cannot select this session as you have already selected a session for this timeslot');
    } else {
      pre_selection = $(checkbox).val(); 
    } 
  } else {
    // if the checkbox we untick is the original checkbox, clear the pre_selection variable
    if (pre_selection == $(checkbox).val())
    {
      pre_selection = '';
    }
  }
}

var session_showing = false;

function _load_timetable_choices()
{
  /* need this delay so if they choose a custom registration type
    from the complete package, code will get it's time to untick
    the 'complete' package radio button
  */

  t = setTimeout(function(){

    if ($('#regcomplete').is(':checked') === true || ($('#id_P').is(':checked') === true && $('#regcomplete').is(':checked') !== true))
    {

      if (session_showing === false)
      {
         session_showing = true;
         ltc_options = 'Pre';
         if (typeof timetable_options != 'undefined')
         {
           /* this is done because the posted values are not passed back
            to the ajax query so we need to manually pass it in the
            ajax call
            */
           pre_selection = timetable_options;
         }

         if (typeof timetable_options == "undefined")
         {
           timetable_options = '';

         }
  
         /* setTimeout added so that when old contents dissappear,
         new contents won't appear until the fade out animation is completed */
         $session_selection.animate({opacity: 'hide', height: 'hide'}, 'slow', function(){
           t = setTimeout(function(){
             // post the data to the loadTimetable function
  
             $.post("conference/loadTimetable", 'options='+ltc_options+"&timetable_options="+timetable_options, function(data){
               $session_selection.html(data).animate({opacity: 'show', height: 'show'}, 'slow');
               $session_selection.prev().animate({opacity: 'show', height: 'show'}, 'slow');
             });
           }, 200);
         });
      } else {
         $session_selection.prev().animate({opacity: 'show', height: 'show'}, 'slow');
      }
    } else  {
      session_showing = false;
      $session_selection.animate({opacity: 'hide', height: 'hide'}, 'slow');
      $session_selection.prev().animate({opacity: 'hide', height: 'hide'}, 'slow');
    }
  }, 100);
}



function _set_checkbox_options()
{
  options = '';
    // check which options the user selected
    if ($('#id_P').is(':checked'))
    {
      options += 'Pre';
      seperater = ',';
    }
    
   /* if ($('#id_Want_to_options3').is(':checked'))
    {
      options += seperater + 'ALL3';
      seperater = ',';
    } else {
      if ($('#id_Want_to_options0').is(':checked'))
      {
        options += seperater + 'D1';
        seperater = ',';
      }
      
      if ($('#id_Want_to_options1').is(':checked'))
      {
        options += seperater + 'D2';
        seperater = ',';
      }
      
      if ($('#id_Want_to_options2').is(':checked'))
      {
        options += seperater + 'D3';
        seperater = ',';
      }
    }
    
    if ($('#id_Want_to_options4').is(':checked'))
    {
      options += seperater + 'M';
    }   */
    
    return options;
}

// ------------------------------------------------------------------------

/**
* Show / hide Other Profession Field
*/
$(document).ready(
		function(){
       show_hide_other_field('id_org_title', 'id_other_field');
       show_hide_other_field('id_org_state', 'id_org_other_state');
       show_hide_other_field('id_state', 'id_other_state');
       show_hide_other_field('id_invoice_state', 'id_invoice_other_state');
	});

/**
 * function figures out who the parent row is before passing
 * execution to the process_other_field function.
 *  
 * function also sets up the change handler    
 */
function show_hide_other_field(parent, child)
{                  
   if (jQuery("#"+child).length > 0)
   {
      var other_field_parent = $('#'+child);
      other_field_parent = other_field_parent.parent();
      $(other_field_parent).hide('fast');
      _process_other_field("#"+parent, other_field_parent, child);
      
      $("#"+parent).change(function() 
      {
          _process_other_field(this, other_field_parent, child);
      });
   } 
}
/**
 * function executes jquery animation to show or hide the 'other' field as appropriate
 */	
function _process_other_field(object, other_field_parent, other_field)
{
  if ($(object).val() == 'Other')
  {
    if ($("#"+other_field).val().toLowerCase() == 'ignore')
    {
      $("#"+other_field).val('');
    }
    $(other_field_parent).animate({opacity: 'show', height: 'show'}, 'slow');
  } else {

    $(other_field_parent).animate({opacity: 'hide', height: 'hide'}, 'slow', function(){
      t = setTimeout(function(){
        $("#"+other_field).val("ignore");
      }, 200);
    });
  }

}

// ------------------------------------------------------------------------

/**
* disable submit by making fields readonly
*/
$(document).ready(
		function(){
		   if (typeof disable_submit != 'undefined' && disable_submit === true)
   	   {
   	    $('input[type=text]', this).attr('disabled', 'disabled');
   	    $('input[type=checkbox]', this).attr('disabled', 'disabled');
   	    $('input[type=radio]', this).attr('disabled', 'disabled');
   	    $('input[type=email]', this).attr('disabled', 'disabled');
   	    $('textarea', this).attr('disabled', 'disabled');
   	    $('select', this).attr('disabled', 'disabled');
       } 
	});


// ------------------------------------------------------------------------

/**
* sgd competition
*/
$(document).ready(
	function(){
	   if ($('#device_selection_label').length > 0)
	   {
         $('#id_device_selection').change(function()
         {
            set_device_label();
         });
         set_device_label();
	   }
});
	
function set_device_label()
{
   dropdown_selection = $('#id_device_selection').find('option').filter(':selected').text();

   text_label = "Tell us about your situation and how you would benefit from winning the <span id='device_selection_label'>" +
      dropdown_selection +
      "</span>?<span>*</span>";
      
   // if this field errors, set the appropriate label in the error message
   $('#device_selection_label').text(dropdown_selection);
   
   // set the entire label next to textarea
   $('#label_situation').html(text_label);
   
}

// ------------------------------------------------------------------------

	/**
	* Control Panel
	*/

	$(document).ready(function() {
		initWebControlPanel();
	});

	function initWebControlPanel()
	{
      // add this item to the featured list
	   jQuery(".addFeaturedLink").click(function (e) {
	      if ($(this).attr('isLoading')=='Y')
			{
			   return;
			}
         $(this).attr({'isLoading': 'Y'});

	   	var id = $(this).attr('id')
	   	id = id.replace('addFeaturedLink', '');
	      var elem = $(this);

	      elem.text('One moment...');

			$.post("/suggestion/addAsFeatsure", {id:id},
				function(datax){

				   elem.parent().fadeTo(200, 0, function()
						{
						   elem.parent().fadeTo(200, 1);
							elem.replaceWith('<span class="addFeaturedLinkDone glowgreen">Item has been added to the featured list</span>');


							$(".removeFeaturedLinkDone").replaceWith('<a id="removeFeaturedLink'+id+'" class="removeFeaturedLink" href="'+ CURRENT_URL+'#remove-as-feature">Remove item</a>');

						}
					);
				}
			);
	   });

      // remove this item from the list
      $('.removeFeaturedLink').click(function(e){

         if ($(this).attr('isLoading')=='Y')
   			{
   			   return;
   			}
            $(this).attr({'isLoading': 'Y'});

   	   	var id = $(this).attr('id')
   	   	id = id.replace('removeFeaturedLink', '');
   	      var elem = $(this);

   	      elem.text('One moment...');

   	      $.post("/suggestion/removeAsFeature", {id:id},
   				function(data){

   				   elem.parent().fadeTo(200, 0, function()
   						{
   						   elem.parent().fadeTo(200, 1);
   							elem.replaceWith('<span class="removeFeaturedLinkDone">Item has been removed</span>');
   							$(".addFeaturedLinkDone").replaceWith('<a id="addFeaturedLink'+id+'" class="addFeaturedLink" href="'+CURRENT_URL+'#add-item-as-feature">Add item</a>');
   						}
   					);
   				}
   			);
      });

      var success_elem = $("#green_alert");

      // check if we need to hide the green_alert div
      if (success_elem.length > 0 && (typeof show_alert != undefined))
      {
         $(success_elem).hide('fast');
      }

	   if ($('#save_button').length > 0)
	   {
         $('#save_button').click(function(){
            // save the data
            $.post("/suggestion/updateFeaturedList",  $("#form1").serialize(),function(data){

               $(success_elem).hide('slow');
               t2 = setTimeout(function(){
                  $('response', data).each(function(node) {
                     var msg = '';

                     if (parseInt($(this).find('id_count').text()) > 0)
                     {
                        msg = 'Feature List Successfully Updated!';
                        //alert(parseInt($(this).find('featured_list_total').text()));
                        if (parseInt($(this).find('featured_list_total').text()) > 0)
                        {

                           // remove the rows
                           $(this).find('id_list').each(function(){

                              $("#row"+$(this).find('id').text()).fadeOut('slow', function(){
                                 $('#row'+$(this).find('id').text()).remove();
                              });

                           });
                        } else {

                           $('#report').fadeOut('slow');
                           msg += ' There are no more items in the featured list.';
                        }


                     } else {

                        // nothing was update
                        msg = 'No nodes were updated.';
                     }

                     // scroll to the top of the page
                     $('html, body').animate({scrollTop:0}, 'slow');

                     // start 200ms delay
                      t = setTimeout(function(){
                           // update the success message
                           $(".green_alert_content").html(msg);

                            // start 1100ms delay
                            t3 = setTimeout(function(){
                                 // show the message
                                   $(success_elem).show('slow');
                               }, 500); // t3
                      }, 400); // t1
                  });
               }, 200); // t2


            });

         });
	   }
	}

// ------------------------------------------------------------------------

	/**
	* Timezone controls
	*/

	$(document).ready(function() {
      $("#id_state").change(function(){
         set_timezone('id_state', 'id_timezones');
      });

      $("#id_org_state").change(function(){
         set_timezone('id_org_state', 'id_org_timezones');
      });
	});

   function set_timezone(state_dropdown, timezone)
   {
      if ($('#'+timezone).length > 0)
      {
         index = 0;
         switch ($('#'+state_dropdown+" option:selected").val())
         {
            case 'ACT':
            case 'TAS':
            case 'VIC':
            case 'NSW': index = 4; break;
            case 'NT':  index = 1; break;
            case 'QLD': index = 2; break;
            case 'SA':  index = 3; break;
            case 'WA':  index = 0; break;
         }
         $("#"+timezone)[0].selectedIndex = index;
      }
   }
   
   
// ------------------------------------------------------------------------

/**
* Product Item List Divider actions
*/

	/**
   * Setup events for the toggling of product item categories
   */
   jQuery(document).ready(function($){

      // Return when printing
      if (CURRENT_DISPLAY_MODE=='print') return;
      
      // Hide all rows first (do it via js so that they're not hidden if js is disabled)
      $("#content table.productlist .product-item-row").css('display', 'none');

      // Remove the 'open' style to each one (which is there by default for print and no js etc)
      $("#content table.productlist .product-item-divider-open").removeClass('product-item-divider-open');
      
      // Add 'toggle all' events
      $("#toggle-all-product-dividers").click(function(){
         var expanded = $(this).hasClass('all-expanded');
         if (expanded) {
            $(this).text('expand all');
            $(this).removeClass('all-expanded');
         } else {
            $(this).text('collapse all');
            $(this).addClass('all-expanded');
         }
         $("#content table.productlist .product-item-divider").each(function(){
            showProductDividerGroup($(this), !expanded);
         });
      });

      // Add click event to each divider link - so that it'll show it's items when clicked
      $("#content table.productlist .product-item-divider").click(function(){
         showProductDividerGroup($(this));
      });
   });

   /**
	* Toggles a product divider's child items
	*
	* Pass in the dividers <a> element, and an optional true:expand, false:collapse
   */
   function showProductDividerGroup($dividerObj, forceOpenOrClose)
   {
      var dividerID = $dividerObj.attr('id').replace('product-divider-', '');
      var childRows = "#content table.productlist tr.category-"+ dividerID;

      // If forceOpenOrClose is not sent - check the divider's class to see what to do
      if (forceOpenOrClose==undefined)
      {
         forceOpenOrClose = !$dividerObj.hasClass('product-item-divider-open');
      }

      if (forceOpenOrClose)
      {
         $dividerObj.addClass('product-item-divider-open');
         $(childRows).show();
         $dividerObj.find("i").text("Click to collapse");
      }
      else
      {
         $dividerObj.removeClass('product-item-divider-open');
         $(childRows).hide();
         $dividerObj.find("i").text("Click to expand");
      }
   }