
/* Valid and send form contact us*/
function contactUs(baseUrl)
{  
	//document.forms["ContactIndexForm"].submit();return;
	var data = $("#ContactIndexForm").serialize();
    $.ajax({
		type: "POST",
        url: baseUrl+"contacts/sendmail",
		data: data,		// Form variables
		dataType: "json",	// Expected response type

		success: function(response, status) {
			
			 // Response was a success
			if (response.success === true) {
				alert(response.data);
 				clearFormContact();

			// Response contains errors
			} else {
				var errors = new Array;
 
				if (typeof(response.data) == ("object" || "array")) {
					$.each(response.data, function(key, value) {
						var text = (isNaN(key)) ? key +": "+ value : value;
 
						errors[errors.length] = text;
					});
				} else {
					errors[errors.length] = response.data ;
				}
 
				errors = errors.join("\n");
				alert(errors);
				


			}

		},
		

		error: function(response, status) {
			alert('An unexpected error has occurred!');
		}


        });
                   
    return false;

}
	function clearFormContact()
		{           
			document.forms["ContactIndexForm"].nomComplet.value="";
			document.forms["ContactIndexForm"].age.value="";
			document.forms["ContactIndexForm"].sexe.value="Femme";
			document.forms["ContactIndexForm"].courriel.value="";
			document.forms["ContactIndexForm"].tel.value="";
			document.forms["ContactIndexForm"].objectif.value="";
			document.forms["ContactIndexForm"].remarque.value="";
			document.forms["ContactIndexForm"].autre.value="";
			
			var selectCondi = document.forms["ContactIndexForm"].condi;
			for (var i=0; i<selectCondi.length; i++) {
				
	  			if (selectCondi[i].checked) {
	 				document.forms["ContactIndexForm"].condi[i].checked= false;
	  			}
			  }	
	
		}
	function printFriendly(baseUrl)
	{ 
	var url=baseUrl+"groups/printfriendly";
	
   		$(".printfriendly").each(
			function(x){
		
			 $.ajax({
               type: "GET",
               url: baseUrl+"groups/printfriendly",

               beforeSend: function(){

                    $("div.printWindow").html("<label>&nbsp;</label><span style='color:#555555;'>Please wait...</span>");

                    

                },

                success: function(msg){

                    eval.call($("div.printWindow").html('<iframe src ="'+url+'" width="100%" height="100%" scrolling="auto" ></iframe>'));

                }

            }).responseText;
			}

		);

		
   }
 /* Valid and send form friend email*/
function inviteAmi(baseUrl)
{  

	var data = $("#MembreInviteamiForm").serialize();
    $.ajax({
		type: "POST",
        url: baseUrl+"membres/inviteami",
		data: data,		// Form variables
		dataType: "json",	// Expected response type

		success: function(response, status) {
			
			 // Response was a success
			if (response.success === true) {
				alert(response.data);
 				clearFormInviteAmi();

			// Response contains errors
			} else {
				var errors = new Array;
 
				if (typeof(response.data) == ("object" || "array")) {
					$.each(response.data, function(key, value) {
						var text = (isNaN(key)) ? key +": "+ value : value;
 
						errors[errors.length] = text;
					});
				} else {
					errors[errors.length] = response.data ;
				}
 
				errors = errors.join("\n");
				alert(errors);
				


			}

		},
		

		error: function(response, status) {
			alert('An unexpected error has occurred!');
		}


        });
                   
    return false;

}
	function clearFormInviteAmi()
		{           
			document.forms["MembreInviteamiForm"].nom.value="Nom";
			document.forms["MembreInviteamiForm"].courriel.value="Courriel";
	
		}
