function isValidEmail(email){
	
    var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/
    if(RegExp.test(email)){
        return true;
    }else{
        return false;
    }
}
function sendContact(){
    var fname=$('#fname').val();
    var lname=$('#lname').val();
    var email=$('#email').val();
    var phone=$('#phone').val();
    var valid=1;

    $('.errorField').each(function(){
        $(this).removeClass('errorField').addClass('bg_input');
    });

    if(fname==''){
        valid=0;
        $('#fname').attr('class', 'errorField');
    }
    if(lname==''){
        valid=0;
        $('#lname').attr('class', 'errorField');
    }
    if(email==''){
        valid=0;
        $('#email').attr('class', 'errorField');
    } else if(!isValidEmail(email)){
        valid=0;
        $('#email').attr('class', 'errorField');
    }
    if(phone==''){
        valid=0;
        $('#phone').attr('class', 'errorField');
    }
    if(valid==0){
		
        $('#error_msg').html('Please fill all fields highlighted in red.');
    } else {
		/***********************************************/
		
		showBox();
		//$('#error_msg').html('') ;
		/************************************************/
		
		
        
		/*********************************************/


        var pars=$('#contactform').serialize();
		
        //$.postwith('process_form.php',pars,Response);
		//////////////////////////////////////////
		
		$.ajax({
   type: "POST",
   url: "http://www.demersbanquethall.com/wp-content/themes/demers/process_form.php",
   data: pars,
   success: function(msg){
   $("#error_msg").ajaxComplete(function(event, request, settings){


//$('#error_msg').html(msg) ;
if (msg==1)
{
	
	window.location = "http://www.demersbanquethall.com/thankyou";

}
else
{
	document.body.removeChild(document.getElementById('layer'));
    document.body.removeChild(document.getElementById('box'));
	showBox2(msg);
	
	
}

//$('#error_msg').remove();

$('form')[0].reset();

});//////end of ajaxcomplete

}///end of success

 });///end of ajax
   ///////////////////////////////////////////////////////////////////
   
    }
    function Response(data){
        
        $('.errorField').each(function(){
            $(this).removeClass('errorField').addClass('bg_input');
        });
        $('form')[0].reset();
    }
    return false;
}
function showBox()
{
  var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;

  var layer = document.createElement('div');
  layer.style.zIndex = 2;
  layer.id = 'layer';
  layer.style.position = 'absolute';
  layer.style.top = '0px';
  layer.style.left = '0px';
  layer.style.height = document.documentElement.scrollHeight + 'px';
  layer.style.width = width + 'px';
  layer.style.backgroundColor = 'black';
  layer.style.opacity = '.6';
  layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)");
  document.body.appendChild(layer);

  var div = document.createElement('div');
  div.style.zIndex = 3;
  div.id = 'box';
  div.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed';
//  div.style.margin='auto';
  div.style.top = '200px';
  div.style.left = (width / 2) - (100 / 2) + 'px'; 
  div.style.height = '20px';
  div.style.width = '100px';
  div.style.backgroundColor = 'white';
  div.style.border = '2px solid silver';
  div.style.padding = '20px';
  document.body.appendChild(div);
  
 /* var a = document.createElement('a');
  a.innerHTML ='Close window';
  
  a.href = 'javascript:void(0)';
   a.onclick = function()
  {
    document.body.removeChild(document.getElementById('layer'));
    document.body.removeChild(document.getElementById('box'));
  };
 
  div.appendChild(a);*/

  var p = document.createElement('h4');
  p.innerHTML = "<p align=\"center\" style=\" margin:auto\">Sending...</p>";
  div.appendChild(p);

  
 
}
function showBox2(msg)
{
  var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;

  var layer = document.createElement('div');
  layer.style.zIndex = 2;
  layer.id = 'layer2';
  layer.style.position = 'absolute';
  layer.style.top = '0px';
  layer.style.left = '0px';
  layer.style.height = document.documentElement.scrollHeight + 'px';
  layer.style.width = width + 'px';
  layer.style.backgroundColor = 'black';
  layer.style.opacity = '.6';
  layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)");
  document.body.appendChild(layer);

  var div = document.createElement('div');
  div.style.zIndex = 3;
  div.id = 'box2';
  div.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed';
//  div.style.margin='auto';
  div.style.top = '200px';
  div.style.left = (width / 2) - (400 / 2) + 'px'; 
  div.style.height = '200px';
  div.style.width = '400px';
  div.style.backgroundColor = 'white';
  div.style.border = '2px solid silver';
  div.style.padding = '20px';
  document.body.appendChild(div);
  
 var a = document.createElement('a');
  a.innerHTML ='Close window';
  
  a.href = 'javascript:void(0)';
   a.onclick = function()
  {
    document.body.removeChild(document.getElementById('layer2'));
    document.body.removeChild(document.getElementById('box2'));
  };
 
  div.appendChild(a);

  var p = document.createElement('p');
  p.innerHTML = "<p  style=\" pading: 10px 10px 10px 10px\">"+ msg +"</p>";
  div.appendChild(p);

  
 
}
