// JavaScript Document
		// for Dependant Form
		
		// clear the cookie upon page load
		setCookie('displayCount', 0, 0.007, '', '', '');
		
		var showFormNum = 1; // number of form showing to begin with.
		var displayForm = showFormNum + 1;
		var openCount = 0;

		// this loop sets all remaining form to disappear
		for (var x=displayForm; x<=10; x++){
			$('.dependantForm' + x).css({ display: 'none'});
		}
		
		// when addForm is clicked, show 1 form, and displayForm iterates. 
		// and once it has displayed the 10th, hide the button.
		
		function addBenefit() {
				
				/*var cookieCount = parseInt(getCookie('displayCount'));
				/*if(!cookieCount){
					$('.dependantForm' + displayForm).css({ display: 'block'});
					displayForm += 1;
					setCookie('displayCount', displayForm, 0.007, '', '', '');
					alert('1');
				}
				else{
					alert('2');
					/*
					$('.dependantForm' + cookieCount).css({ display: 'block'});
					cookieCount += 1;
					setCookie('displayCount', cookieCount, 0.007, '', '', '');
					*/
					// loops and find all % field is empty.
					openCount = 0;
					for(i=1;i<=10;i++){
						if($('.dependantForm' + i + ' .inputAdd').val() != ''){
							openCount += 1;
						}
					}
					//alert(openCount);
					openCount += 1; //this is nhext one to be opened
					$('.dependantForm' + openCount).css({ display: 'block'});
					setCookie('displayCount', openCount, 0.007, '', '', '');
					
				//}
				if(openCount == 10){
					$('.addForm a img').css({display:'none'});
				}
				
				return false;
		}
		// nb: issue with the above function is that the forms are accummulative - 
		// so if they added >10 forms and submitted, and want to change it again...
		// they can't.

		
		function setTotal() {
			var value = 0;
			
			$("input.inputAdd").each(function() {
				var inputAddVal = $(this).val()
				if(inputAddVal == '') {
					inputAddVal = 0;
				}
				else if (inputAddVal.match(/^\d+$/) && inputAddVal != 0) {
					value = eval(value) + eval(inputAddVal); 
				} else {					
					$("input.errorTextJS").val("You can only enter numbers")
				}
			});
			
			$("input.inputSub").each(function() {
				var inputSubVal = $(this).val()
				if(inputSubVal == '') {
					inputSubVal = 0;
				}
				else if (inputSubVal.match(/^\d+$/) || inputSubVal != 0) {
					value = eval(value) - eval(inputSubVal); 
				} else {					
					$("input.errorTextJS").val("You can only enter numbers")
				}
			});
							
			$("input.inputTotal").val(value)
			
			if (value > 100) {
				$("input.inputTotal").addClass("inputError")				
				$("input.errorTextJS").val("The total must add up to 100%")
				}
			else {
				$("input.inputTotal").removeClass("inputError")
				$("input.errorTextJS").val("")
				}
				
		}
	
	// when ready.
	$(document).ready(function(){
	
		// for monthly performance tableCloth
	    $('#monthlyPerformance').tableHover({colClass: 'hover'}); 
		 
		 // for glossary
		 $('.glossary_listings_ul li a').each(function(){
			 $(this).toggle(function(){
				$(this).parent("li").children("div").css({display: "block"});
			 },
			 function(){
			 	$(this).parent("li").children("div").css({display: "none"});
			 });
		 });
		
				
		// redirect to glossary page
		var url = new String(document.location);
		var urlparts = url.split('=');
		var identifier = urlparts[2];
		
		$('.glossary_listings_ul li div').each(function(){
			if($(this).attr("id") == identifier){
				$(this).css({display: "block"});
			}
		});

				
    });
		
		
