folderAndScript = '/includes/lib/action.php';


function $(v){ return document.getElementById(v); }

function showArchives(){
	
	//new Effect.SlideDown("archives_section");
	//$('btn_view_archives').style.display = 'none';	
	
	jQuery("#archives_section").show("slow");
	jQuery("#btn_view_archives").fadeOut("slow");
}

function validateForm(p_sForm){
	
	var f = $(p_sForm);
	
	var msg = 'The Following fields are required:\n';
	var out = msg;
	
	if(f.program_title != null){
		 if(f.program_title.selectedIndex == 0)
		 	out += '- ' +f.program_title.title + '\n'; 
	}
	if(f.program_sub_title != null){
		 if(f.program_sub_title.selectedIndex == 0){
			if($('outreachform') == null)
			 	out += '- ' +f.program_sub_title.title + '\n'; 
		 }
	}
	
	for(i=0; i<f.elements.length; i++){
	
		switch(f.elements[i].accessKey){
			case '1': 
						highlightField(f.elements[i],false);
						if(!validateField(f.elements[i],'any')){
							out += '- ' +f.elements[i].title + '\n'; 
							highlightField(f.elements[i],true);
						}
						break;
			
			case '2': highlightField(f.elements[i],false);
						if(!validateField(f.elements[i],'email')){
							out += '- Valid ' +f.elements[i].title + '\n'; 
							highlightField(f.elements[i],true);
						}
						break;
						
		}
		 
	}
	
	
	
							

	if(out != msg)
		alert(out);
	else
		return true;
		
	return false;
	
}

function validateField(p_oField,p_sType){
	
	if(p_sType == 'any'){
		return !checkEmpty(p_oField.value);
	}else if(p_sType == 'email'){
		if(checkEmpty(p_oField.value))
			return false;
		return echeck(p_oField.value);
	}
	
	//p_oField.style.background = '
	
}

function highlightField(p_oField,p_bDo) { 	
	if(p_bDo)
		p_oField.style.backgroundColor = '#FFFBE8';
	else
		p_oField.style.backgroundColor = '#ffffff';
}

function checkEmpty(p_sVal){
	l_sVal = escape(p_sVal);
	l_sVal = l_sVal.replace(/\s*((\S+\s*)*)/, "$1");
	l_sVal = l_sVal.replace(/((\s*\S+)*)\s*/, "$1");
	return l_sVal.length < 1;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}


/* Form Dropdowns */

function loadDropDown(p_oField,p_nID){
	 
	f = $(p_oField);
	
	if((obj = $('subprogram_list')) != null)
		obj.value = '';
	
	foptions = eval('dropdownPair_'+ p_nID + '_top');
	
	f[0] =  new Option('Select...','',true);
	
	for(i=0; i<foptions.length; i++){
		f[i+1] =  new Option(foptions[i],foptions[i],false);
	}
	  
	document.currentDropDownID = p_nID;
	if( $('program_sub_title')) {
		$('program_sub_title')[0] =  new Option('','',true);
		$('program_sub_title').disabled = true;
	}
	
}

function dropdownUpdate(p_oField,p_oNewField,p_nID){
	if(p_nID == -1)
		p_nID = document.currentDropDownID;
	f = $(p_oField);
	f2 = $(p_oNewField);
	selectedID = f.selectedIndex;
	output = '';

	if((obj = $('subprogram_list')) != null)
		obj.value = '';
		
	foptions = eval('dropdownPair_'+ p_nID);
	foptions = foptions[selectedID];
	
	if(p_nID == 3 || p_nID == 4){
		$('area_interest').style.display = 'none';
		$('program_sub_title').style.display = 'block';
		if(selectedID == 6){
			$('area_interest').style.display = 'block';
			$('program_sub_title').style.display = 'none';
			 
			return;
		}
	}
	
	if(foptions == null){
		f2.innerHTML = '';
		f2.disabled = true;
		return;
	}
	 
	if(p_nID != 2)
		f2[0] =  new Option('Select...','',true);
	else
		$('form_2_message').innerHTML = "";
		
	for(i=0; i<foptions.length; i++){
			if(p_nID == 2)
				f2[i+1] =  new Option(foptions[i],foptions[i],false); // titile
			else
				f2[i+1] =  new Option(foptions[i],foptions[i],false);
	}
	
	//output +=  '<option value="" title="'+foptions[i]+'">'+foptions[i]+'</option>'+"\n";
	 
	f2.disabled = false;
	
	if(selectedID == 0)
		f2.disabled = true;
		
	if(p_nID == 2){
		$('form_2_message').innerHTML = "<strong>Select one or more</strong>";
	}
	
	
}
            
dropdownPair_1 = new Array();			
//dropdownPair_1_top = new Array('PreK and Kindergarten','First - Third Grade','Third - Fifth Grade','Middle and High School','Nature for all Seasons');


dropdownPair_1_top = new Array('Animal Homes','Fur, Feathers, Slimey and Scaley','Nature Explorer','Pond & Stream','Tall, Tall Trees','Birds of a Feather','Flowers, Leaves and Growing Green','Bugs Abound','Amazing Animals','Have to Have a Habitat','Life of the Lenape - Basic (1.5 hours)','Life of the Lenape - Extended (2.5 hours)','Watersheds','Ecosystems','Discovering Dirt','Rock & Roll','Conservation','Biodiversity');

//dropdownPair_1[1] = new Array('Animal Homes','Reptiles and Amphibians','Fur, Feathers, Slimey and Scaley','Nature Explorer','Pond & Stream');
//dropdownPair_1[2] = new Array('Amazing Animals','Pond & Stream','Have to Have a Habitat','Fur, Feathers, Slimey and Scaley','Life of the Lenape - Basic (1.5 hours)','Life of the Lenape - Extended (2.5 hours)');
//dropdownPair_1[3] = new Array('Watersheds','Ecosystems','Discovering Dirt','Rock & Roll','Conservation','Life of the Lenape - Basic (1.5 hours)','Life of the Lenape - Extended (2.5 hours)');
//dropdownPair_1[4] = new Array('Watersheds','Ecosystems','Biodiversity','Conservation','Life of the Lenape - Basic (1.5 hours)','Life of the Lenape - Extended (2.5 hours)');
//dropdownPair_1[5] = new Array('Entire Four Part Series','Birds of a Feather (Winter)','Flowers, Leaves and Growing Green (Spring)','Bugs Abound (Summer)','Tall, Tall Trees (Fall)');


dropdownPair_2 = new Array();			
dropdownPair_2_top = new Array('Animal Adaptations','Habitats and Ecosystems','Animal Kingdom','Reptiles & Amphibians','Mammals','Birds','Insects');
//dropdownPair_2[5] = new Array('Reptiles &amp; Amphibians',,);



            
dropdownPair_3 = new Array();			
dropdownPair_3_top = new Array('Badge Program ($100)','Night Hike and Campfire ($150)','Big Red Barn Overnight ($350)','Overnight & Program ($400)','Overnight, Program & Night hike ($450)','Service Program');

dropdownPair_3[1] = new Array('Tiger Cub: Let\'s Go Outdoors','Wolf Cub: Your Living World','Bear Cub: Sharing your World with Wildlife','Webelos: Naturalist','Webelos: Forester','Webelos: Geologist' );
dropdownPair_3[4] = new Array('Tiger Cub: Let\'s Go Outdoors','Wolf Cub: Your Living World','Bear Cub: Sharing your World with Wildlife','Webelos: Naturalist','Webelos: Forester','Webelos: Geologist');
dropdownPair_3[5] = new Array('Tiger Cub: Let\'s Go Outdoors','Wolf Cub: Your Living World','Bear Cub: Sharing your World with Wildlife','Webelos: Naturalist','Webelos: Forester','Webelos: Geologist');


dropdownPair_4 = new Array();			
dropdownPair_4_top = new Array('Badge Program ($100)','Night Hike and Campfire ($150)','Big Red Barn Overnight ($350)','Overnight & Program ($400)','Overnight, Program & Night hike ($450)','Service Program');

dropdownPair_4[1] = new Array('Brownie Try-Its: Eco-Explorer','Brownie Try-Its: Watching Wildlife','Brownie Try-Its: Water Everywhere','Brownie Try-Its: Earth and Sky','Junior Badges: Earth Connections','Junior Badges: Earth Wildlife','Junior Badges: Rocks Rock','Girl Scouts: All About Birds');
dropdownPair_4[4] = new Array('Brownie Try-Its: Eco-Explorer','Brownie Try-Its: Watching Wildlife','Brownie Try-Its: Water Everywhere','Brownie Try-Its: Earth and Sky','Junior Badges: Earth Connections','Junior Badges: Earth Wildlife','Junior Badges: Rocks Rock','Girl Scouts: All About Birds');
dropdownPair_4[5] = new Array('Brownie Try-Its: Eco-Explorer','Brownie Try-Its: Watching Wildlife','Brownie Try-Its: Water Everywhere','Brownie Try-Its: Earth and Sky','Junior Badges: Earth Connections','Junior Badges: Earth Wildlife','Junior Badges: Rocks Rock','Girl Scouts: All About Birds');







function checkAllNone(p_xInput,p_sID){
	
	var i = 1;
	var l_bCheckedValue = false;
	if(p_xInput.checked)
		 l_bCheckedValue = true;
		
	
	while($(p_sID+i) != null){
			$(p_sID+i).checked = l_bCheckedValue;
			i++;
	}
}
 
 
function checkAllNoneWeekOf(p_xInput,p_nStart,p_nEnd){
	
	var i = p_nStart;
	var l_bCheckedValue = false;
	if(p_xInput.checked)
		 l_bCheckedValue = true;
		
	
	while($('Weekof_'+i) != null && i <= p_nEnd ){
			 
			$('Weekof_'+i).checked = l_bCheckedValue;
			i++;
	}
	UpdateNatureForm();
}

function weeksCalc(p_xField,p_nValue,p_sField,p_sViewField){
	var l_xField = $(p_sField);
	var l_xViewField = $(p_sViewField);
	
	var v = parseInt(p_xField.value);
	v = v * p_nValue;
			
	l_xField.value = v;
	if(v > 0)
		l_xViewField.innerHTML =  '<strong>Total:</strong> 	$'+v;
	else
		l_xViewField.innerHTML =  '';

}


function selectListHiddenUpdate(p_xField,p_sField){
	var l_xField = $(p_sField);
	var l_aItems = new Array();;
	
	for(var i=0; i<p_xField.length; i++)
		if(p_xField[i].selected)
			l_aItems.push(p_xField[i].title)
			
	l_xField.value = l_aItems.join(",");

}


function daysCalc(p_sField1,p_sField2,p_nAmount,p_sHidden,p_sShow){
	 
	var l_xField1 = $(p_sField1);
	var l_xField2 = $(p_sField2);
	var l_xHiddenField = $(p_sHidden);
	var l_xShowField = $(p_sShow);
	
	
	var v1 = parseInt(l_xField1.value);
	v1 = v1 * p_nAmount;
		

	var v2 = parseInt(l_xField2.value);
	v2 = v2 * 20;
 
	if(!(v1 >0))
		v1 = 0;
	
	if(!(v2 >0))
		v2 = 0;
		
	var totalValue = v1 + v2;
			
	l_xHiddenField.value = v1 + v2;
	if(totalValue > 0)
		l_xShowField.innerHTML =  '<strong>Total:</strong> 	$'+(totalValue);
	else
		l_xShowField.innerHTML =  '';
		
		
		
	
}


_xMembershipApplication = {
	
	init : function(){
		this.updateTotals();
		$("input[@name='member_dollar_amount']").click( function(){ _xMembershipApplication.updateTotals(); });
		$("#member_dollar_amount_other").keyup( function(){ _xMembershipApplication.updateTotals(); });
		
		$("input[@name='gift_dollar_amount']").click( function(){ _xMembershipApplication.updateTotals(); });
		$("#gift_dollar_amount_other").keyup( function(){ _xMembershipApplication.updateTotals(); });
	},
	
	updateTotals : function(){
		if($("input[@name='member_dollar_amount']:checked").attr('rel') == 'other'){
			var l_nAmount = parseInt($("#member_dollar_amount_other").val().toString().replace(/[^0-9]/gi,""));
		}else{
			var l_nAmount = parseInt($("input[@name='member_dollar_amount']:checked").val().toString().replace(/[^0-9]/gi,""));
			$("#member_dollar_amount_other").val(0);
		}
			
		if($("input[@name='gift_dollar_amount']:checked").attr('rel') == 'other'){
			var l_nGiftAmount = parseInt($("#gift_dollar_amount_other").val().toString().replace(/[^0-9]/gi,""));
		}else{
			var l_nGiftAmount = parseInt($("input[@name='gift_dollar_amount']:checked").val().toString().replace(/[^0-9]/gi,""));	
			$("#gift_dollar_amount_other").val(0);
		}
		
		$('#membership-payment').html('$'+l_nAmount+".00");
		$('#gift-payment').html('$'+l_nGiftAmount+".00");
		$('#total-payment').html('$'+(l_nAmount + l_nGiftAmount)+".00");
		$('#dollar_amount').val((l_nAmount + l_nGiftAmount)+".00");
		
		//dollar_amount_other
		//gift_dollar_amount_other
		//gift_dollar_amount
	}	
	
	
	
}

 
 
function calulateTotalAmount(){
	
	
	var l_xAllWeeks = $('allweeks');
	//var l_x4th = $('4thweek');
	var l_xExtended = $('extended');
	var l_xTotalWeeks = $('totalweeks');
	var l_xDepositPaid = $('paid');
	var l_xTotalAmount = $('totalAmount');
	var l_xAmount =	$('dollar_amount_due');
	
	 
	if(isNaN(l_xAllWeeks.value)) l_xAllWeeks.value = 0;
	//if(isNaN(l_x4th.value)) 
	
	if(isNaN(l_xExtended.value)) l_xExtended.value = 0;
	if(isNaN(l_xTotalWeeks.value)) l_xTotalWeeks.value = 0;
	if(isNaN(l_xDepositPaid.value) ) l_xDepositPaid.value = 0;
	 
	
	//var l_nDeposit =  l_xTotalWeeks.value * 100;
	var l_nDeposit = 0;
	var l_nTotalDue = parseInt(l_xAllWeeks.value) + parseInt(l_xExtended.value) + parseInt(l_nDeposit);
	l_xAmount.value = (parseInt(l_nTotalDue) - parseInt(l_xDepositPaid.value));
	l_xTotalAmount.innerHTML = '$'+ l_xAmount.value;
	
	jQuery('.input_amount_1').each( function() {
			jQuery(this).val(l_xTotalWeeks.value * 100);		
			
										 
	});
	
	jQuery('.input_amount_2').each( function() {
			jQuery(this).attr('value',l_xAllWeeks.value);		
			});
	
	jQuery('#pay_deposit').html('$' + (l_xTotalWeeks.value * 100));
	jQuery('#pay_total').html('$' + (parseInt(l_xAllWeeks.value) + parseInt(l_xExtended.value)));

}

_xNatureForm = {

	init : function(){
		
		$j('.updateNatureForm').click( function(){ 
			_xNatureForm.updateForm($(this));
		});
		
		$j('.updateNatureFormAll').click( function(){ 
			if($j(this).attr('checked'))
				$j(this).parent().find('.updateNatureForm').attr('checked',true);
			else
				$j(this).parent().find('.updateNatureForm').attr('checked',false);
			
			_xNatureForm.calculateTotals();
		});
		
		$j('.member-radio').click( function(){ 
			_xNatureForm.calculateTotals();
		});
		
		 _xNatureForm.calculateTotals();
		 
	},
	
	updateForm : function(p_xObj){
		var l_nCount = $j(p_xObj).parent().find('.updateNatureForm').length;
		var l_nFoundCount = 0;
		$j(p_xObj).parent().find('.updateNatureForm').each( function(){
			if( $j(this).attr('checked') == true){
				l_nFoundCount++;
			}
		});
		if(l_nCount ==  l_nFoundCount ){
			$j(p_xObj).parent().find('.updateNatureFormAll').attr('checked',true);
			$j(p_xObj).parent().find('.updateNatureForm').attr('checked',true);
		}else{
			$j(p_xObj).parent().find('.updateNatureFormAll').attr('checked',false);	
		}
		_xNatureForm.calculateTotals();
	},
	
	calculateTotals : function(){
		var l_nAmount = 0;
		
		var l_bMember = 'non';
		var l_sDetails = '';
		
		$j('.member-radio').each( function(){				
			if($j(this).attr('checked')){
				if($j(this).val() == 'Member')
					l_bMember = 'member';
				else
					l_bMember = 'non';
			}
		});
		 
		var l_aPricing = new Array();
		
		l_aPricing['member'] = 18;
		l_aPricing['non'] = 20;
		
		l_aPricing[0] = new Array(); //fall
		l_aPricing[1] = new Array(); //winter
		l_aPricing[2] = new Array(); //spring
		l_aPricing[3] = new Array(); //summer
		
		l_aPricing[0]['name'] = 'Fall';
		l_aPricing[0]['member'] = 160;
		l_aPricing[0]['non'] = 180;
		l_aPricing[1]['name'] = 'Winter';
		l_aPricing[1]['member'] = 180;
		l_aPricing[1]['non'] = 200;
		l_aPricing[2]['name'] = 'Spring';
		l_aPricing[2]['member'] = 120;
		l_aPricing[2]['non'] = 140;
		l_aPricing[3]['name'] = 'Summer';
		l_aPricing[3]['member'] = 120;
		l_aPricing[3]['non'] = 140;
		
		$j('.season-section').each( function(){
			var l_nSeason = $j(this).attr('rel');
			if( $j(this).find('.updateNatureFormAll').attr('checked')){
				l_nAmount += l_aPricing[l_nSeason][l_bMember];
				l_sDetails += "All "+l_aPricing[l_nSeason]['name']+" Sessions<br />\n";
			}else{
				var l_nCheckedCount = 0;
				$j(this).find('.updateNatureForm').each( function(){
					if($j(this).attr('checked')){
						l_nCheckedCount++;
					}
				});
			 	if(l_nCheckedCount > 0){
					l_nAmount += (l_aPricing[l_bMember] * l_nCheckedCount);
					l_sDetails += l_nCheckedCount + " "+l_aPricing[l_nSeason]['name']+" Sessions<br />\n";
				}
			}
		});
		 
		$j('#session_details').html(l_sDetails + "<br />\n<strong>Amount:</strong> $" + l_nAmount);
		$j('#dollar_amount').val(l_nAmount);
	
	}
	
}
function UpdateNatureForm(){
	
	  
 
	var l_nAmount = 0; 
	var l_bCalcFallWeeks = true;
	var l_nPriceFallFull = 180;
	var l_bCalcWinterWeeks = true;
	var l_nPriceWinterFull = 180;
	var l_bCalcSpringWeeks = true;
	var l_nPriceSpringFull = 100;
	var l_bCalcSummerWeeks = true;
	var l_nPriceSummerFull = 120;
	var l_nPriceWeek = 20;
	var l_sDetails = '';

	if($('type_member').checked){
		l_nPriceFallFull = 160;
		l_nPriceWinterFull = 160;
		l_nPriceSpringFull = 90;
		l_nPriceSummerFull = 108;
		l_nPriceWeek = 18;
	}
	

	if( $('Weekof_1').checked ){
		l_nAmount += l_nPriceFallFull;
		l_bCalcFallWeeks = false;
		l_sDetails += "All Fall Sessions<br />\n";
	}
	if( $('Weekof_12').checked ){
		l_nAmount += l_nPriceWinterFull;
		l_bCalcWinterWeeks = false;
		l_sDetails += "All Winter Sessions<br />\n";
	}
	if( $('Weekof_23').checked ){
		l_nAmount += l_nPriceSpringFull;
		l_bCalcSpringWeeks = false;
		l_sDetails += "All Spring Sessions<br />\n";
	}
	if( $('Weekof_30').checked ){
		l_nAmount += l_nPriceSummerFull;
		l_bCalcSummerWeeks = false;
		l_sDetails += "All Summer Sessions<br />\n";
	}
		 
		 
		
	if(l_bCalcFallWeeks){
		i = 2; p_nEnd = 11;
		var count =0;
		while($('Weekof_'+i) != null && i <= p_nEnd ){
				if($('Weekof_'+i).checked){
					l_nAmount += l_nPriceWeek;
					count++;
				}
				i++;
		}
		l_sDetails += count + " Fall Weeks<br />\n";
	}
	if(l_bCalcWinterWeeks){
		i = 13; p_nEnd = 22;
		var count =0;
		while($('Weekof_'+i) != null && i <= p_nEnd ){
				if($('Weekof_'+i).checked){
					l_nAmount += l_nPriceWeek;
					count++;
				}
				i++;
		}
		l_sDetails += count + " Winter Weeks<br />\n";
	}
	if(l_bCalcSpringWeeks){
		i = 24; p_nEnd = 29;
		var count =0;
		while($('Weekof_'+i) != null && i <= p_nEnd ){
				if($('Weekof_'+i).checked){
					l_nAmount += l_nPriceWeek;
					count++;
				}
				i++;
		}
		l_sDetails += count + " Spring Weeks<br />\n";
	}
	if(l_bCalcSummerWeeks){
		i = 31; p_nEnd = 37;
		var count =0;
		while($('Weekof_'+i) != null && i <= p_nEnd ){
				if($('Weekof_'+i).checked){
					l_nAmount += l_nPriceWeek;
					count++;
				}
				i++;
		}
		l_sDetails += count + " Summer Weeks<br />\n";
	}
		 
	$('session_details').innerHTML = l_sDetails + "<br />\n<strong>Amount:</strong> $" + l_nAmount;
	$('dollar_amount').value = l_nAmount;

}

function getCalendar(m,y){
	
	setClientCallback('Loading Content...');
	qs = 'a=showCalendar';
	qs += '&m='+m;
	qs += '&y='+y;
	
	client.makeRequest(folderAndScript,qs);
}


function setClientCallback(p_sMsg){
	client = new HttpClient(); client.isAsync = true; client.requestType = 'POST'; client.statusDiv = 'HttpClientStatus_notice';
	client.callback = function(result) {
		//l_xStatus.innerHTML = '';l_xStatus.style.display = 'block';
		eval(result); 
	}
	l_xStatus = $(client.statusDiv);
	l_xStatus.innerHTML = p_sMsg;
	
}
 
 
function viewCampsList(hidediv,showdiv){
	$(hidediv).style.display = 'none';
	$(showdiv).style.display = 'block';
	new Effect.SlideDown(showdiv);

		
}


_xEvent = {
	
	init : function(){
		$('#amount').attr('disabled','').css('opacity','1.00');
		$('#taxdonation').attr('disabled','disabled').css('opacity','0.30');
	},
	
	validateForm : function(p_xForm){
		 
		var l_sFormname = $(p_xForm).attr('id');
		if(l_sFormname == 'form-renewal'){
			
			if( checkEmpty ($('#fullname').val()) ){
				alert('Please Enter your name');
				$('#fullname').focus();
				return false;
			}
			
			if( checkEmpty ($('#company').val()) ){
				alert('Please Enter your company');
				$('#company').focus();
				return false;
			}
			
			if( checkEmpty ($('#guests').val()) ){
				alert('Please list your guests, or enter "None"');
				$('#guests').focus();
				return false;
			}
			  
		}
		
		if(  $('#attend:checked').val() == 'Yes' ){
			$('#dollar_amount').val($('#amount').val());
		}else{
			$('#dollar_amount').val($('#taxdonation').val());
		} 
		
		return true;	
	},
	
	attend : function(p_xFormItem){
		var l_sVal = $(p_xFormItem).val();
		$('#amount').attr('disabled','').css('opacity','1.00');
		$('#taxdonation').attr('disabled','').css('opacity','1.00');
		if(l_sVal == 'No'){
			$('#amount').val('0.00').attr('disabled','disabled').css('opacity','0.30');
		}else if(l_sVal == 'Yes'){
			$('#taxdonation').val('0.00').attr('disabled','disabled').css('opacity','0.30');
		}
		
	}
	


}






















_xSummerCamp = {
	
	init : function(){
		 
		j('.group-box').find('input').click(function(){ _xSummerCamp.updateTotals(); });
		j('#ext_days_mem,#deposit_paid').keyup(function(){ _xSummerCamp.updateTotals(); });
		 
		j('.payment_options input').click(function(){ _xSummerCamp.updateTotals(); });
		
		_xSummerCamp.updateTotals();
		  
	},
	
	updateTotals : function(){
		 var l_nValue = 0;
		 var l_nCount = 0;
		 var l_nExtended = parseInt(j('#ext_days_mem').val());
		 if(!l_nExtended > 0)
		 	l_nExtended = 0;
			
		var l_nDepositPaid = parseInt(j('#deposit_paid').val());
		 if(!l_nDepositPaid > 0)
		 	l_nDepositPaid = 0;
			
		 
		
		 j('.group-box').find('input').each( function(){
			if( j(this).attr('checked')){
				l_nValue += parseInt(j(this).attr('rel'));
				l_nCount++;
			}
		 });
		 l_nExtended *= 100;
		 
		 var l_nTotal = l_nExtended + l_nValue + (l_nCount*100);
		 var l_nTotalDue = l_nExtended + l_nValue + (l_nCount*100) - l_nDepositPaid;
		 j('#final-total-weeks').html(l_nCount);
		 j('#final-total-weeks-price').html(l_nCount*100);
		 j('#final-total-fee-for-weeks').html(l_nValue);
		 j('#final-total-fee-for-extended').html(l_nExtended);
		 j('#final-total-fee-1').html( l_nTotal );
		 j('#final-total-fee-due').html( l_nTotalDue );
		 j('#final-total-fee-due-amount').val(l_nTotalDue);
		 j('#total-fee-due').val(l_nTotalDue);
		 j('#total-deposit-due').val(l_nCount*100);
		  
		 j('#payment_full_amount').html(l_nTotalDue);
		 j('#payment_deposit_amount').html(l_nCount*100);
		 j('#usepaypal').val(1);
		
		 if( j('.payment_options_amount input:checked').val() != 'Balance' ){
			j('#final-total-fee-due-amount').val(l_nCount*100);	
		 }
		 if( j('.payment_options_type input:checked').val() != 'Paypal' ){
			j('#usepaypal').val(0);
		 }
		 
		//alert( j('.payment_options_type input:checked').val() );
		  
		 j('.payment_options input').each( function(){
													
													
		});
		
		 
		 
		//payment_type_option
                   
		 
	}
	
	
}





_xUtils = {
	
	checkEmpty : function(p_sVal){
		l_sVal = escape(p_sVal);
		l_sVal = l_sVal.replace(/\s*((\S+\s*)*)/, "$1");
		l_sVal = l_sVal.replace(/((\s*\S+)*)\s*/, "$1");
		return l_sVal.length < 1;
	}
	,
	checkEmail : function(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){ return false }
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ return false }
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ return false }
		if (str.indexOf(at,(lat+1))!=-1){ return false }
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ return false }
		if (str.indexOf(dot,(lat+2))==-1){ return false }
		if (str.indexOf(" ")!=-1){ return false }
		return true					
	},
	checkAlphaNumeric : function(p_sVal){
		return !(/[^a-zA-Z0-9]/.test(p_sVal));	
	}
	
}

/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Base64 = {
 
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
 
	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = Base64._utf8_encode(input);
 
		while (i < input.length) {
 
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
 
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
 
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
 
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
 
		}
 
		return output;
	},
 
	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
		while (i < input.length) {
 
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
 
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
 
			output = output + String.fromCharCode(chr1);
 
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
 
		}
 
		output = Base64._utf8_decode(output);
 
		return output;
 
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}



function serialize( mixed_value ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Arpad Ray (mailto:arpad@php.net)
    // +   improved by: Dino
    // +   bugfixed by: Andrej Pavlovic
    // +   bugfixed by: Garagoth
    // %          note: We feel the main purpose of this function should be to ease the transport of data between php & js
    // %          note: Aiming for PHP-compatibility, we have to translate objects to arrays
    // *     example 1: serialize(['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: 'a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}'
    // *     example 2: serialize({firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'});
    // *     returns 2: 'a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}'
 
    var _getType = function( inp ) {
        var type = typeof inp, match;
        var key;
        if (type == 'object' && !inp) {
            return 'null';
        }
        if (type == "object") {
            if (!inp.constructor) {
                return 'object';
            }
            var cons = inp.constructor.toString();
            if (match = cons.match(/(\w+)\(/)) {
                cons = match[1].toLowerCase();
            }
            var types = ["boolean", "number", "string", "array"];
            for (key in types) {
                if (cons == types[key]) {
                    type = types[key];
                    break;
                }
            }
        }
        return type;
    };
    var type = _getType(mixed_value);
    var val, ktype = '';
    
    switch (type) {
        case "function": 
            val = ""; 
            break;
        case "undefined":
            val = "N";
            break;
        case "boolean":
            val = "b:" + (mixed_value ? "1" : "0");
            break;
        case "number":
            val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value;
            break;
        case "string":
            val = "s:" + mixed_value.length + ":\"" + mixed_value + "\"";
            break;
        case "array":
        case "object":
            val = "a";
            /*
            if (type == "object") {
                var objname = mixed_value.constructor.toString().match(/(\w+)\(\)/);
                if (objname == undefined) {
                    return;
                }
                objname[1] = serialize(objname[1]);
                val = "O" + objname[1].substring(1, objname[1].length - 1);
            }
            */
            var count = 0;
            var vals = "";
            var okey;
            var key;
            for (key in mixed_value) {
                ktype = _getType(mixed_value[key]);
                if (ktype == "function") { 
                    continue; 
                }
                
                okey = (key.match(/^[0-9]+$/) ? parseInt(key) : key);
                vals += serialize(okey) +
                        serialize(mixed_value[key]);
                count++;
            }
            val += ":" + count + ":{" + vals + "}";
            break;
    }
    if (type != "object" && type != "array") val += ";";
    return val;
}


