// JavaScript Document
$(document).ready(function(){
	
	$('#submitme, #hilitebox').hide();
	$('#hide_zp').hide();
	$('.dropdown').hide();
	
	$('.chkdropdown').click(function() {	
									 
		var checked =$(this).is(':checked'); 
	
		var divid = 'div'+$(this).attr("id");
		if (checked) {
			
			$('#'+divid).show();
			
		} else { 
		
			$('#' + divid).hide();
			$("#" + divid).children("input[@type=text]").val(""); 
		
		}

	});
	
	//var auchecked = $(".grpaupd:checked").val();
	if ($(".grpaupd:checked").val()==null) $('#next1').hide();
	//Check if radio group has been selected, hide next button if not 
	
    //If radio button state changes, show next button
	$('.grpaupd').click(function() {
															 
		$('#next1').show();
														 
	});
	
	var page_count = 1; //must be at least one page
	
		//Functions
	$('.prevbutton').click(function(){changePage(this, -1);});
	$('.nextbutton').click(function(){changePage(this, 1);});
	
	// Loop through each DIV - if it is a page hide all except page1
		// Looks for DIVs starting with "page" so careful how you name your divs

	$('div').each(function(){
		var div_id = $(this).attr("id");

		if (div_id) {  // Is the ID set? If yes, check value of ID for page
			if (div_id.substr(0,4)=="page" && div_id != "page1") {
				$('#'+div_id).hide();    // all pages except page1
				page_count++;			 //increment page count
			}
		}
	 });

	$("#showall").click(function() {
		$('.page_layout').show();
		$('.showme, .buttons').hide(); 	
		$("#hilitebox").css("display", "block");

		$('#submitme, #hilitebox').show();  
		$("#chkAgree").attr( {disabled : 'disabled'});
		scroll(0,0);
	});



	// Function changes page - next or previous
	function changePage(obj, direction) {
		// obj is button pressed, direction - either 1 (next) or -1 (prev)
		var curpage = $(obj).parent().parent().attr("id");  // Page div
		var pagenum = curpage.substr(4);   //Strip off page number - eg page1 = 1
		if (isNaN(pagenum)) {alert("Unknown page number"); return;}
		nextpage = (pagenum*1)+(direction*1);   //determine next page number
		//We going to hide the current page then show the next page, either up or down
		if ((direction*1)==1) {
			//do some validation
			current = pagenum;
			//if (!v.form()) return;
		}
		//if (v.form()) alert("Valid");
		$("#"+curpage).hide();
		$("#page" + nextpage).show();
		//Update the breadcrumb classes
		

	}
	
	if ($("#chkAgree:checked").val()==null) $('#next2').hide();
	/*var agreeCheck = $("#chkAgree")
	
	agreeCheck.is(":checked")
			? $('input#next2').attr( { disabled : "" } )
			: $('input#next2').attr( { disabled : 'disabled' } );*/

	$("#chkAgree").click(function() {

		  if (this.checked == true) {
			  $('#next2').show();
			  //$('input#next2').attr( { disabled : "" } );
		  } else {
			  alert("You must agree to the terms and conditions to continue with this form");
			  $('input#next2').hide();
		  }
	});

//end  - don't add anything below
});