// JavaScript Document

function Validate()	{
	

	var formErrors = true;
	//$(form).find("input")
	$('.reqfield',document.forms[0]).each(function(){
		if (!$(this).val().length) {
			
				$(this).keydown(function() {
					$(this).next().css("display","none");
				});
				$(this).next().css("display","block");
				//alert($(this).next());
				formErrors = false;
		}
	})
	
	
	return formErrors;
}


function PrepareForm() {
	
   $("#contactSubmit").click(function(){
   		return (Validate());
 	});
   

   if ( !(/MSIE (7)/.test(navigator.userAgent) && navigator.platform == "Win32") ) {
   	   /*$('dl').addClass("narrow").not($(".special")).css("display","none");
	   $('dd').not($(".show")).css("display","none");*/
	   $('dl').addClass("narrow").css("display","none");
	   $('dd').css("display","none");
	   
	   
	   
	  $('dt').attr("title", "Click to show").addClass("toggler").toggle(function() {
			$(this).attr("title", "Click to hide").addClass("down").next().slideDown('fast');
			/*var innertest =  $(this).data( 'lastToggle');
			console.log(innertest);*/
	  }, function() {
			$(this).attr("title", "Click to show").removeClass("down").next().slideUp('fast');
			
	  }).lastToggle = 1;
	  
	  $('h2').attr("title", "Click to show").addClass("toggler").toggle(function() {
			$(this).attr("title", "Click to hide").addClass("down").next().slideDown('fast');
	  }, function() {
			$(this).attr("title", "Click to show").removeClass("down").next().slideUp('fast');
	  });
	  $("h2#basic").trigger("click");
	   $("dl#special dt").trigger("click");
	   
   }
   
   var myFile = document.location.toString();
	if (myFile.match('#')) { // the URL contains an anchor
	// click the navigation item corresponding to the anchor
	var myAnchor = '#' + myFile.split('#')[1];
  	$(myAnchor).trigger("click").parent().prev('h2').trigger("click");
	}
	   
	   //target ie7
	   /*if ((window.XMLHttpRequest != undefined) && (ActiveXObject != undefined)) {
		   $('dt').each ( function() {
				$(this).css('display', 'inline');
			});
	   }*/
	   /*var outertest = $('dt#large').data;
	   console.log(outertest);*/
	   
	  
	  //TODO re-implement this. it is more user-friendly
	  /*$('#showall').toggle(function() {			
			$(this).html("Hide all questions");
			$('dl').css("display","block");
			$('dd').css("display","block");
			/*$('h2').each() {
				if (!($(this).is('.down'))) {
					
				}
			}*/
			/*$('h2').attr("title", "Click to hide").addClass("down");
			$('dt').attr("title", "Click to hide").addClass("down");
	  }, function() {
			$(this).html("Show all questions");
			$('dl').css("display","none");
			$('dd').css("display","none");
			$('h2').attr("title", "Click to show").removeClass("down");
			$('dt').attr("title", "Click to show").removeClass("down");				
	  });*/
	  
	   
   //}
 }
 

  $(document).ready(PrepareForm);