    function IsEmail(email) {
            var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (regex.test(email)) return true;
            else return false; } 


$(document).ready(function() 
{
  //Enter the content in to contact form
  $.post("/qcontact.htm", {}, function(content)
  {
    $('#qccontact').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
    $('#qccontact').draggable( 
    { 
      zIndex:    20,  
      opacity: 0.7, 
      handle: '#qccontacthandle', 
      cursor: 'move'
    });
     
        
    //Contact box to dissapear  on click
    $('#qcclose').click(function(e) 
    { 
        e.preventDefault();
        $("#qccontact").fadeOut(700);
        $('#layer').hide();
        $("#layer").height(1);
        $("#layer").width(1); 
    }); 
     
    //Contact box to appear on click
    $('.qccontactus').click(function(e) 
    {   
        e.preventDefault();
        scrollToTopPlease();
        displayContact();
    }); 
      
    function displayContact()
    {
        if(!$('#qccontact').is(':visible'))
        {
          $('#qccontacterror').html("");
          $('#layer').show();
          $("#qccontact").fadeIn(700);
          $("#layer").height($(document).height());
          $("#layer").width($(document).width());
        }
    }
      
    //Submit the form
    $('#qcsubmit').click(function(e)
    {
      e.preventDefault();
      
      //Validate
      var qcname=$('#qcname').val();
      var qccompname=$('#qccompname').val();
      var qcemail=$('#qcemail').val();
      var qctel=$('#qctel').val();
      var qcquery=$('#qcquery').val();
      
      var error="";
      if(qcname.length<5) { error+="Enter name<br />"; }
      if(qccompname.length<5) { error+="Enter company name<br />"; }
      if(qcemail.length<2) { error+="Enter email address<br />"; }
        else if(!IsEmail(qcemail)) { error+="Enter valid email address<br />"; }
      if(qcquery.length<5) { error+="Enter enquiry<br />"; }
      //Display error
      if(error!="")
      {
        $('#qccontacterror').html("<strong>Please complete the following:</strong><br />"+error);
      }
      else
      {
        //or post via AJAX and get thank you message
        $.post("/ajax/ajaxcontact.php", {name: qcname, compname: qccompname, email: qcemail, tel: qctel, enquiry: qcquery}, function(content)
        {
          $('#qccontactcontent').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);
}
