/**
 * @author admin
 */

function ExecuteMe(){
	 
	//var uniquePath = "/inetprocesscomlatest/"; // offline
	 var uniquePath = "/";// for inetprocess.com
	var queryString = $('#formulairecontact').formSerialize();
	
	$.ajax({
          url: uniquePath+'contactmail.php', type: 'POST', timeout: 3000,
          data:  queryString,
          complete: function(){
		  	$.blockUI({
				message: '<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.',
				css: {
					width: '310px',
					border: '1px solid #dadbda'
				}
			} );
			
				setTimeout(function() { $.unblockUI({ fadeTime: "slow" }) },3000);
			//alert(data.responseText);
		  },
		   success: function(msg){
		     //alert( "Data Saved: " + msg );
		   }
      });
     
}
$(document).ready(
  function() {
      // envoi du formulaire de contact
	 //var uniquePath = "/inetprocesscomlatest/"; // offline
	 var uniquePath = "/";// for inetprocess.com
	  //var uniquePath = "/inetprocess"; // for devweb.inetcrm.com/inetprocess/
	  //var uniquePath = "/projects/inetprocesscomsvn/"; // offline
      var options = {
          url: uniquePath+'contactmail.php', type: 'POST', timeout: 3000,
          beforeSubmit: validatecontact,
		  cache: false,
          //complete: ExecuteMe,
		   //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({
				message: '<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>',
				css: {
					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({
				message: '<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>',
				css: {
					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);
	  
	  var dmsOptions = {
          url: uniquePath+'contactmail.php', type: 'POST', timeout: 3000,
          beforeSubmit: validatecontact_dms,
		  cache: false,
          complete: function(data) {
		  	$.blockUI({
				message: '<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>',
				css: {
					width: '310px',
					border: '1px solid #dadbda'
				}
			} );
            setTimeout(function() { $.unblockUI({ fadeTime: "slow" }) },3000);
			//alert(data.responseText);
          },
		   success: function(msg){
		     //alert( "Data Saved: " + msg );
		   }
      };
	  $('#formulairecontact_dms').ajaxForm(dmsOptions);
	  
	  var crmOptions = {
          url: uniquePath+'contactmail.php', type: 'POST', timeout: 3000,
          beforeSubmit: validatecontact_crm,
		  cache: false,
          complete: function(data) {
		  	$.blockUI({
				message: '<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>',
				css: {
					width: '310px',
					border: '1px solid #dadbda'
				}
			});
            setTimeout(function() { $.unblockUI({ fadeTime: "slow" }) },3000);
			//alert(data.responseText);
          },
		   success: function(msg){
		     //alert( "Data Saved: " + msg );
		   }
      };
	$('#formulairecontact_crm').ajaxForm(crmOptions);
	var inetktreportOptions = {
          url: uniquePath+'contactmail.php', type: 'POST', timeout: 3000,
          beforeSubmit: validatecontact_ktreport,
		  cache: false,
          complete: function(data) {
		  	$.blockUI({
				message: '<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>',
				css: {
					width: '310px',
					border: '1px solid #dadbda'
				}
			});
            setTimeout(function() { $.unblockUI({ fadeTime: "slow" }) },3000);
			//alert(data.responseText);
          },
		   success: function(msg){
		     //alert( "Data Saved: " + msg );
		   }
      };
      $('#formulairecontact_ktreport').ajaxForm(inetktreportOptions);
  }
)


function validatecontact() {
  $('.inputform').css({ borderColor: '#dadbda', backgroundColor: 'white' });
  var yellowbg='#FFFF82';
//var uniquePath = "/inetprocesscomlatest/"; // offline
 var uniquePath = "/";// for inetprocess.com
  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;
	
  } else if ($('#6_letters_code').val()=='') {
    alert('Please enter code.');
    $('#6_letters_code').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;
  }else if ($('#6_letters_code').val()!='') {
  	
	//added by ajoshi 30-6-2010 --> Start
	$.ajax({
		   type: "GET",
		   url: uniquePath+"chk_capcha.php",   // send the data for captcha validation
		   data: "from=capcha&cap_code=" + document.getElementById('6_letters_code').value,
		 
		   success: function(msg){
		    // alert( "Data Saved: " + msg );
			 if(msg=="No"){
			 	alert("Captcha code does not match. Enter again.");
				var img = document.images['captchaimg'];
				img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
			 	//return false;
				
			 }
			  if(msg=="Yes"){
			 	//alert("ashish-yes");
			 	ExecuteMe();
				//return true;
			 }
		   }
});
	//added by ajoshi 30-6-2010 --> End
	
	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 ($('#tel_inetdocs').val()=='') {
    alert('Please enter a valid phone number.');
    $('#tel_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 validatecontact_dms() {
  $('.inputform').css({ borderColor: '#dadbda', backgroundColor: 'white' });
  var yellowbg='#FFFF82';

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

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

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

  } else if (!matchRegularExpression($('#email_dms').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_dms').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;

/*
  } else if ($.trim($('#message_dms').val())=='') {
    alert('Please enter a message.');
    $('#message_dms').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;
*/
  }
}
function validatecontact_crm() {
  $('.inputform').css({ borderColor: '#dadbda', backgroundColor: 'white' });
  var yellowbg='#FFFF82';

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

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

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

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

  } else if (!matchRegularExpression($('#email_crm').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_crm').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;
/*

  } else if ($.trim($('#message_crm').val())=='') {
    alert('Please enter a message.');
    $('#message_crm').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;
*/
  }
}
function validatecontact_ktreport() {
  $('.inputform').css({ borderColor: '#dadbda', backgroundColor: 'white' });
  var yellowbg='#FFFF82';

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

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

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

  } else if (!matchRegularExpression($('#email_ktreport').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_ktreport').css({ borderColor: 'red', backgroundColor: yellowbg }).focus();
    return false;

  } /*
else if ($.trim($('#message_ktreport').val())=='') {
    alert('Please enter a message.');
    $('#message_ktreport').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;
	
  } 
}