jQuery(document).ready(function(){
	
		
		
			/*		function inscription_panier(){
						var email = jQuery('#inscription_panier input[id=email]').value;
						var mdp = jQuery('#connection_panier input[id=mdp]').value;
						var Name = jQuery('#inscription_panier input[id=name]').value;
						var firstname = jQuery('#connection_panier input[id=firstname]').value;		
						alert(email+"-"+mdp+"-"+Name+"-"+firstname);
					}	*/
	
	
	jQuery('#pass1').keyup(function(){
				evalPwd(this.value);
	});
	
	jQuery('#disconnection').click(function(){
		jQuery.ajax({
				url: "logout.php",
				success: function(msg){
					document.location.reload();
					return false;
				}
		});
		return false;
	});
	
	jQuery('#login').click(function(){
		var val_login = jQuery('#account_login').attr("value");
		var val_pass = jQuery('#account_pass').attr("value");
		
		jQuery.ajax({
				type: "POST",
				url: "login.php",
				data: "login="+val_login+"&pass="+val_pass,
				success: function(msg){
					document.location.reload();
					return false;
				}
		});
		return false;
	});

	
	/*jQuery('.flags').children('img').click(function(){
		var language = jQuery(this).attr("alt");
		
		jQuery.ajax({
				type: "POST",
				url: "language.php",
				data: "language="+language,
				success: function(msg){
					location.reload();
				}
		});
		return false;
	});*/
	

	jQuery('#connection_panier_btn').click(function(){
			var email = jQuery(this).parent().children("input").attr("value");
			var mdp = jQuery(this).parent().children("input[id=mdp]").attr("value");
			jQuery.post("valide_identification_panier.php", { types: "connection", email: email, mdp: mdp },
  		function(data){
  			//alert(data);
  			if(data.statut == '0'){
  				alert(data.erreur);
  			}else{
  				if(data.types=="wanted"){
  					document.location = "panier-validation.php?type=wanted"
  				}else if(data.types=="annonce"){
  					if(data.id_type_annonce=='11' || data.id_type_annonce=='8' || data.id_type_annonce=='12'){
  						document.location = "panier-validation.php?type=annonce"
  					}else{
  						document.location = "panier-paiement.php";
  					}
  				}
  			}
  			},"json");
			return false;						
		});
					
				
		jQuery('#inscription_panier_btn').click(function(){
			var email = jQuery(this).parent().children("input[id=email]").attr("value");
			var mdp = jQuery(this).parent().children("input[id=mdp]").attr("value");
			var nom = jQuery(this).parent().children("input[id=name]").attr("value");
			var prenom = jQuery(this).parent().children("input[id=firstname]").attr("value");
			//alert(email+"-"+mdp+"-"+nom+"-"+prenom);
			
			jQuery.ajax({
				type: 'POST',
				url: 'valide_identification_panier.php',
				data: jQuery('#inscription_panier').serialize() + '&types=inscription', //'types=inscription&email='+email+'&mdp='+mdp+'&nom='+nom+'&prenom='+prenom,
				success: function(data){
					//alert(data.erreur);
					if(data.statut == '0')
					{
						alert(data.erreur);
					}
					else
					{
						if(data.types=="wanted")
						{
							document.location = "panier-validation.php?type=wanted"
						}
						else if(data.types=="annonce")
						{
							if( (data.id_type_annonce=='11') || (data.id_type_annonce=='8') || (data.id_type_annonce=='12') )
							{
								document.location = "panier-validation.php?type=annonce"
							}
							else
							{
								document.location = "panier-paiement.php";
								document.location = "panier-paiement.php";
							}
						}
					}
				},
				error: function(data)
				{
					alert('error');				
				},
				dataType: 'json'
			});
			
	/*		jQuery.post("valide_identification_panier.php", { types: "inscription", email: email, mdp: mdp, nom: nom, prenom: prenom  },
  		function(data){
  			//alert(data);
  			if(data.error != null){
  				alert(data.error);
  			}else{
  				if(data.types=="wanted"){
  					document.location = "panier-validation.php?type=wanted"
  				}else if(data.types=="annonce"){
  					if(data.id_type_annonce=='11' || data.id_type_annonce=='8' || data.id_type_annonce=='12'){
  						document.location = "panier-validation.php?type=annonce"
  					}else{
  						document.location = "panier-paiement.php";
  					}
  				}
  			}
  			},"json");*/
			return false;						
		});
	

});

function evalPwd(s)
{
	var cmpx = 0;
	
	if (s.length >= 5)
	{
		
		
		if (s.search("[A-Z]") != -1)
		{
			cmpx++;
		}
		
		if (s.search("[a-z]") != -1)
		{
			cmpx++;
		}
		
		if (s.search("[0-9]") != -1)
		{
			cmpx++;
		}
		
		if (s.length >= 8 || s.search("[\x20-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E]") != -1)
		{
			cmpx++;
		}
	}
	
	if (cmpx == 0)
	{
		document.getElementById("weak").className = "nrm";
		document.getElementById("medium").className = "nrm";
		document.getElementById("strong").className = "nrm";
	}
	else if (cmpx == 1)
	{
		document.getElementById("weak").className = "red";
		document.getElementById("medium").className = "nrm";
		document.getElementById("strong").className = "nrm";
	}
	else if (cmpx == 2)
	{
		document.getElementById("weak").className = "yellow";
		document.getElementById("medium").className = "yellow";
		document.getElementById("strong").className = "nrm";
	}
	else
	{
		document.getElementById("weak").className = "green";
		document.getElementById("medium").className = "green";
		document.getElementById("strong").className = "green";
	}
};


function modify_form(type,id){
	jQuery.post(
		"annonce_form_get.php",
		"type="+type+"&id="+id,
		function(data, textStatus){
			//success: 
			jQuery('#form_suite').html(data);
			//jQuery('#form_suite').html(data);
		});
	
};


/*
function modify_form(type_aircraft,id_aircraft){

	
	if(id_aircraft==""){
		id_aircraft=0;
	}
	
	jQuery.getJSON({
            url: "http://aircraft.e-magineurs.fr/annonce_form_get.php",
            data: {type: type_aircraft, id : id_aircraft},
            async:true,
            contentType: "application/json; charset=utf-8",
            dataType: "jsonp",
            success: function(data) {
                   alert('success');
                   jQuery('#form_suite').html(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert('error');
            },
            beforeSend: function (XMLHttpRequest) {
                    alert('Before Send');
            },
            complete: function (XMLHttpRequest, textStatus) {
                    alert('Complete');
                    
            }
	});
};*/