$(document).ready(function() 
{
  //Enter the content in to contact form
  $.post("/brochure.htm", {}, function(content)
  {
    $('#brochure').html(content);
    
    //Resize the layer if visible and the user resizes the window
    $(window).bind("resize", function()
    { 
      if($('#layer').is(':visible'))
      {
       $("#layer").height($(document).height());
       $("#layer").width($(document).width());
      }
    });
        
    //Make the contact box draggable
    $('#brochure').draggable( 
    { 
      zIndex:    20,  
      opacity: 0.7, 
      handle: '#brochurehandle', 
      cursor: 'move'
    });
     
        
    //Contact box to dissapear  on click
    $('#brochureclose').click(function(e) 
    { 
        e.preventDefault();
        $("#brochure").fadeOut(700);
        $('#layer').hide();
        $("#layer").height(1);
        $("#layer").width(1); 
    }); 
     
    //Contact box to appear on click
    $('.brochurerequest').click(function(e) 
    {   
        e.preventDefault();
        scrollToTopPlease();
        displayContact();
    }); 
      
    function displayContact()
    {
        if(!$('#brochure').is(':visible'))
        {
          $('#brochureerror').html("");
          $('#layer').show();
          $("#brochure").fadeIn(700);
          $("#layer").height($(document).height());
          $("#layer").width($(document).width());
        }
    }
      
    //Submit the form
    $('#brochuresubmit').click(function(e)
    {
      e.preventDefault();
      
      //Validate
      var brochurename=$('#brochurename').val();
      var brochurecompname=$('#brochurecompname').val();
      var brochureemail=$('#brochureemail').val();
      if ($('#brochuretick').attr('checked'))
      { var brochuretick="TRUE"; }
      else
      { var brochuretick="FALSE"; }
        
      var error="";
      if(brochurename.length<5) { error+="Enter name<br />"; }
      if(brochurecompname.length<2) { error+="Enter company name<br />"; }
      if(brochureemail.length<2) { error+="Enter email address<br />"; }
        else if(!IsEmail(brochureemail)) { error+="Enter valid email address<br />"; }
      //Display error
      if(error!="")
      {
        $('#brochureerror').html("<strong>Please complete the following:</strong><br />"+error);
      }
      else
      {
        //or post via AJAX and get thank you message
        $.post("/ajax/ajaxbrochure.php", {brochurename: brochurename, brochurecompname: brochurecompname, brochureemail: brochureemail, brochuretick: brochuretick}, function(content)
        {
          $('#brochurecontent').html(content);
        });
      }
    });
  });
});

function setOpacity()
{
  var layer=document.getElementById("layer");
  layer.style.opacity="0.5";
  layer.style.filter="alpha(opacity=50)";
}
   

    
function scrollToTopPlease()
{
 scroll(0,0);
}