//________________________________________________Formulaire nominateForm
$(function() {
	$("#nominateForm").validate({
		rules: {
			passwordItem: {
				required: true
			},
			loginItem: {
				required: true
			}
		},
		messages: {
			passwordItem: "<br /><span style='color:#ff0000;font-size:10px;font-family: Geneva, Arial, Helvetica, sans-serif;'>Code is required</span>",
			loginItem:"<br /><span style='color:#ff0000;font-size:10px;font-family: Geneva, Arial, Helvetica, sans-serif;'>Login is required</span>"
		},
		submitHandler: function() {
				var from = $("#fromItem").val();
		
				var act = 'accessSecureChevalerie';
				
				if (from == 'secure') {
					act = 'login';
				}

				//console.log(from);
				
				$.ajax({
					type: "POST",
					url: "../private/action.php",
					//data: "act=" + act + "&password="+passwordItem+"&login="+loginItem+"&lang=en&type=MEMBER",
					data: {
						act: act,
						login: $("#loginItem").val(),
						password: $("#passwordItem").val(),
						from: 'flash',
						lang: 'en',
						type: 'MEMBER'
					},
					success: function(msg){
						if(msg==3){
							if(from=='rule'){
								urlToReach = '../private/ok.htm';
								urlToReachtype = 'iframe';
								$.nyroModalManual({
									url: urlToReach,
									type:urlToReachtype,
									minWidth:5,
									minHeight:5
								});
							}
							if(from=='decoration'){
								window.open('../private/Chevalerie_Costs_Ordre_de_la_Chevalerie.pdf');
							}
							if(from=='artistic'){
								urlToReach = '../private/ok_artistic.htm';
								urlToReachtype = 'iframe';
								$.nyroModalManual({
									url: urlToReach,
									type:urlToReachtype,
									minWidth:5,
									minHeight:5
								});
							}
							if(from=='travelling'){
								urlToReach = '../private/ok_travelling.htm';
								urlToReachtype = 'iframe';
								$.nyroModalManual({
									url: urlToReach,
									type:urlToReachtype,
									minWidth:5,
									minHeight:5
								});
							}
							
							if(from=='secure'){
								window.location.href = "../private/log_on.php";
							}
							
						}else if(msg==4){
								urlToReach = '../private/ok.htm';
								urlToReachtype = 'iframe';
								$.nyroModalManual({
									url: urlToReach,
									type:urlToReachtype,
									minWidth:5,
									minHeight:5
								});
						} else if (msg == 'log_on') {						
							window.location.href = "../private/log_on.php";
						}else{
							alert('Authentification problem');
						}
					}
				});	
		},									
		meta: "validate"	 
	});
	
	
});	

//________________________________________________Formulaire de contact
function doValidateForm(){
	$("#nominateFormCandidate").validate({
		rules: {
			name: {
				required: true
			},
			fname: {
				required: true
			},
			section: {
				required: true
			},
			telephone: {
				required: true
			}			
		},
		messages: {
			name: '<img src="../private/formulaire_rules/error.gif" alt="error" style="vertical-align:middle; margin-left: 4px;" />',
			fname: '<img src="../private/formulaire_rules/error.gif" alt="error" style="vertical-align:middle; margin-left: 4px;" />',
			section: '<img src="../private/formulaire_rules/error.gif" alt="error" style="vertical-align:middle; margin-left: 4px;" />',
			telephone: '<img src="../private/formulaire_rules/error.gif" alt="error" style="vertical-align:middle; margin-left: 4px;" />'			
		},
		submitHandler: function(form) {
		
			//______________input Text;
			var sectionCategoryItem= $('#sectionCategory').val();
			var nameItem= $('#name').val();
			var fnameItem= $('#fname').val();
			var sectionItem= $('#section').val();
			var functionItem= $('#function').val();
			var birthItem= $('#birth').val();
			var mSinceItem= $('#mSince').val();
			var companyItem= $('#company').val();
			var postcodeItem= $('#postcode').val();
			var townItem= $('#town').val();
			var emailItem= $('#email').val();
			var faxItem= $('#fax').val();
			var professionnal_honoryItem= $('#professionnal_honory').val();
			var ynameItem= $('#yname').val();
			var telephoneItem= $('#telephone').val();
			var presidentItem= $('#president').val();
			var yourMessageItem= $('#yourMessage').val();
			var streetItem= $('#street').val();
			
			//______________input Radio;
			
			var award_catItem = $('input[name=award_cat]:checked').val();
			var inscr_autItem = $('input[name=inscr_aut]:checked').val();
			var choixItem = $('input[name=choix]:checked').val();

			$.ajax({
   				type: "POST",
   				url: "../private/nominate_candidate.php",
   				data: "sectionCategoryItem="+sectionCategoryItem+"&nameItem="+nameItem+"&fnameItem="+fnameItem+"&sectionItem="+sectionItem+"&functionItem="+functionItem+"&birthItem="+birthItem+"&mSinceItem="+mSinceItem+"&companyItem="+companyItem+"&postcodeItem="+postcodeItem+"&townItem="+townItem+"&emailItem="+emailItem+"&faxItem="+faxItem+"&professionnal_honoryItem="+professionnal_honoryItem+"&ynameItem="+ynameItem+"&presidentItem="+presidentItem+"&yourMessageItem="+yourMessageItem+"&award_catItem="+award_catItem+"&inscr_autItem="+inscr_autItem+"&choixItem="+choixItem+"&streetItem="+streetItem+"&telephoneItem="+telephoneItem
   				,success: function(msg){
					//$.nyroModalRemove();
					urlToReach = '../private/formulaire_rules/ok.htm';
					urlToReachtype = 'iframe';
					$.nyroModalManual({
						url: urlToReach,
						type:urlToReachtype,
						minWidth:5,
						minHeight:5
					});					
   				}
 			});	
		},									
		meta: "validate"	 
	});

}
