/**
 * @author admin
 */
$(document).ready(
  function() {
      // envoi du formulaire de contact
	  
	 var uniquePath = "/";// for inetprocess.com
	 //var uniquePath = "/france_current_inetprocesscom/"; // for ajoshi
	  //var uniquePath = "/inetprocess"; // for devweb.inetcrm.com/inetprocess/
	  //var uniquePath = "/projects/inetprocesscomsvn/"; // offline
		//var uniquePath = "/projects/inetprocess/";  //edit dhaivat
      var options = {
          url: uniquePath+'contactmail.php', type: 'POST', timeout: 3000,
          beforeSubmit: validatecontact,
		  cache: false,
          complete: function(data) {
		  	$.blockUI('<div id="sendwaiting"><img src="'+uniquePath+'extension/ezwebin/design/ezwebin/images/inc_images/circle-ball-dark-antialiased.gif" alt="Loading" vspace="10" /><br />The window will close automatically once the form sent.<br />Thank you for your message.</div>', { width: '310px', border: '1px solid #dadbda'} );
            setTimeout(function() { $.unblockUI({ fadeTime: "slow" }) },3000);
			//alert(data.responseText);
          },
		   success: function(msg){
		     //alert( "Data Saved: " + msg );
		   }
      };
      $('#formulairecontact').ajaxForm(options);

	  var demooptions = {
          url: uniquePath+'demomail.php', type: 'POST', timeout: 3000,
          beforeSubmit: validatedemo,
		  cache: false,
          complete: function() {
		  	$.blockUI('<div id="sendwaiting"><img src="'+uniquePath+'extension/ezwebin/design/ezwebin/images/inc_images/circle-ball-dark-antialiased.gif" alt="Loading" vspace="10" /><br />The window will close automatically once the form sent.<br /><strong>Please check your mail for demo site information.</strong></div>', { width: '310px', border: '1px solid #dadbda'} );
            setTimeout(function() { $.unblockUI({ fadeTime: "slow" }) },3000);
			//alert(data);
          }
		  /*
		   to alert the data from php page
		   success: function(msg){
		     //alert( "Data Saved: " + msg );
		   },
		   */
      };
      $('#formulairedemo').ajaxForm(demooptions);
	  
	  
	  
	  
	   var inetdocsOptions = {
          url: uniquePath+'contactmail.php', type: 'POST', timeout: 3000,
          beforeSubmit: validatecontact_inetdocs,
		  cache: false,
          complete: function(data) {
		  	$.blockUI('<div id="sendwaiting"><img src="'+uniquePath+'extension/ezwebin/design/ezwebin/images/inc_images/circle-ball-dark-antialiased.gif" alt="Loading" vspace="10" /><br />The window will close automatically once the form sent.<br />Thank you for your message.</div>', { width: '310px', border: '1px solid #dadbda'} );
            setTimeout(function() { $.unblockUI({ fadeTime: "slow" }) },3000);
			//alert(data.responseText);
          },
		   success: function(msg){
		     //alert( "Data Saved: " + msg );
		   }
      };
      $('#formulairecontact_inetdocs').ajaxForm(inetdocsOptions);
  }
)


function validatecontact() {
  $('.inputform').css({ borderColor: '#dadbda', backgroundColor: 'white' });
  var yellowbg='#FFFF82';

  if ($('#prenom').val()=='') {
    alert('Please enter a name.');
    $('#prenom').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;

  } else if ($('#nom').val()=='') {
    alert('Please enter a surname.');
    $('#nom').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;

  } else if ($('#societe').val()=='') {
    alert('Please enter the company name.');
    $('#societe').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;

  } else if (!matchRegularExpression($('#tel').val(), /^[0-9+\s]*$/g)) {
    alert('Please enter a valid phone number.');
    $('#tel').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;

  } else if (!matchRegularExpression($('#email').val(), /^[a-z\d]+((\.|-|_)[a-z\d]+)*@((?![-\d])[a-z\d-]{0,62}[a-z\d]\.){1,4}[a-z]{2,6}$/gi)) {
    alert('Please enter a valid email.');
    $('#email').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;

  } else if ($.trim($('#message').val())=='') {
    alert('Please enter a message.');
    $('#message').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;
  }
}
//---------------------------------------

function validatecontact_inetdocs() {
  $('.inputform').css({ borderColor: '#dadbda', backgroundColor: 'white' });
  var yellowbg='#FFFF82';

  if ($('#prenom_inetdocs').val()=='') {
    alert('Please enter a name.');
    $('#prenom_inetdocs').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;

  } else if ($('#nom_inetdocs').val()=='') {
    alert('Please enter a surname.');
    $('#nom_inetdocs').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;

  } else if ($('#societe_inetdocs').val()=='') {
    alert('Please enter the company name.');
    $('#societe_inetdocs').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;

  } else if (!matchRegularExpression($('#tel_inetdocs').val(), /^[0-9+\s]*$/g)) {
    alert('Please enter a valid phone number.');
    $('#tel_inetdocs').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;

  } else if (!matchRegularExpression($('#email_inetdocs').val(), /^[a-z\d]+((\.|-|_)[a-z\d]+)*@((?![-\d])[a-z\d-]{0,62}[a-z\d]\.){1,4}[a-z]{2,6}$/gi)) {
    alert('Please enter a valid email.');
    $('#email_inetdocs').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;

  } else if ($.trim($('#message_inetdocs').val())=='') {
    alert('Please enter a message.');
    $('#message_inetdocs').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;
  }
}

//--------------------------------------

function validatedemo() {
  $('.inputform').css({ borderColor: '#dadbda', backgroundColor: 'white' });
  var yellowbg='#FFFF82';

  if ($('#cname').val()=='') {
    alert('Please enter a name.');
    $('#cname').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;
	
  } else if (!matchRegularExpression($('#cemail').val(), /^[a-z\d]+((\.|-|_)[a-z\d]+)*@((?![-\d])[a-z\d-]{0,62}[a-z\d]\.){1,4}[a-z]{2,6}$/gi)) {
    alert('Please enter a valid email.');
    $('#cemail').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;
	
  }else if ($.trim($('#ccontactno').val())=='' || !matchRegularExpression($('#ccontactno').val(), /^[0-9+\s]*$/g)) {
    alert('Please enter a valid contact number.');
    $('#ccontactno').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;
	
  } 
}