$(function() {

  $('<div id="lava"/>').appendTo('#navigation');
  
  $('li', '#navigation').each(function() {
    var $li = $(this);
    var $a = $('a', $li);
    var left = $a.position().left;
    var width = $a.outerWidth();
    $a.mouseover(function() {
      $('#lava').css('width', width).
      stop(true, true).
      animate({
        left: left
      }, 'fast');
      $('#lava').css('border', '1px solid #4E4128');
    });    
  
  
  });
  
  $(".login_submit").click(function() {
		if((document.getElementById('user_name').value == ''))
		{
			document.getElementById('user_name').focus();
			alert("Please enter your name");
			return false;
		}
		if((document.getElementById('user_email').value == ''))
		{
			document.getElementById('user_email').focus();
			alert("Please enter your email address");
			return false;
		}
		if (div_echeck(document.getElementById('user_email').value)==false)
		{
			document.getElementById("user_email").focus();
			alert("Please check your email address");
			return false;
		}
		if((document.form1.comment.value == ''))
		{
			document.form1.comment.focus();
			alert("Please enter your message");
			return false;
		}
		else
		{
			var dataString = $('input[type=\'text\'], input[type=\'hidden\'] , textarea');
			$.ajax({
			type: "POST",
			url: "enquiry-mail.php",
			data: dataString,
			success: function(data){
					alert("We will contact you shortly.");
					document.getElementById('user_name').value = '';		
					document.getElementById('user_email').value = '';		
					document.form1.comment.value = '';		
				}
			});
    	  return false;
  		}
								
  });

	$(".contact_submit").click(function() {
		if((document.getElementById('first_name').value == ''))
		{
			document.getElementById('first_name').focus();
			alert("Please enter your first name");
			return false;
		}
		if((document.getElementById('last_name').value == ''))
		{
			document.getElementById('last_name').focus();
			alert("Please enter your last name");
			return false;
		}
		if((document.getElementById('contact_email').value == ''))
		{
			document.getElementById('contact_email').focus();
			alert("Please enter your email address");
			return false;
		}
		if (div_echeck(document.getElementById('contact_email').value)==false)
		{
			document.getElementById("contact_email").focus();
			alert("Please check your email address");
			return false;
		}
		if((document.getElementById('contact_no').value == ''))
		{
			document.getElementById('contact_no').focus();
			alert("Please enter your Contact Number");
			return false;
		}
		if((document.getElementById('comment').value == ''))
		{
			document.getElementById('comment').focus();
			alert("Please enter your message");
			return false;
		}
		else
		{
			var dataString = $('input[type=\'text\'], input[type=\'hidden\'] , input[type=\'radio\'] , select ,textarea');
			$.ajax({
			type: "POST",
			url: "enquiry-mail.php",
			data: dataString,
			success: function(data){
					alert("We will contact you shortly.");
					window.location = 'Contact-Us.html';
				}
			});
    	  return false;
  		}
								
  });

});

	function div_echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	//	alert("Invalid E-mail ID")
	 //  document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 
		return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	//	alert("Invalid E-mail ID")
	  // document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 
		return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	//	alert("Invalid E-mail ID")
//	   document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 
	  	return false
	}
	 if (str.indexOf(at,(lat+1))!=-1){
	//	alert("Invalid E-mail ID")
//	   document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 
		return false
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
//	   document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 
//	alert("Invalid E-mail ID")
		return false
	 }



	 if (str.indexOf(dot,(lat+2))==-1){

	   //document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 

	//	alert("Invalid E-mail ID")

	     return false

	 }
	 if (str.indexOf(" ")!=-1){
	   	//document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 
	//	alert("Invalid E-mail ID")
	    	return false
	 }
	 return true					

	}

