﻿$(window).load(function() {
	var txt = 'Commander ce mod&egrave;le';
	var txt2 = 'Commander';
	var curl = 'commande.html';
	var cmderr = 'Veuillez compléter tous les champs.';
	var cmdthx = 'Merci, nous vous contacterons sous peu.';
	if (location.href.match(/anglais/)) {
		txt = 'Order this item';
		curl = '/commande-en.html';
		txt2 = 'Order';
		cmderr = 'Please fill all fields.';
		cmdthx = 'Thank you, we will contact you soon.';
	}
	$('object,embed').each(function() {
		
		$(this).after('<div style="text-align:center;padding-bottom:15px;"><a style="background: none repeat scroll 0 0 #CC3333; color: #FFFFFF; padding: 4px; text-decoration: none;" href="'+curl+'">'+txt+'</a></div>');
	});
	
	$('table[width=144]').each(function() {
		$(this).find('td').append('<a style="background: none repeat scroll 0 0 #CC3333; color: #FFFFFF; padding: 4px; text-decoration: none;" href="'+curl+'">'+txt2+'</a>');
	});
	
	$('#commander-form').submit(function() {
		$('#ref').remove();
		$('#commander-form').append('<input id="ref" type="hidden" name="ref" value="'+document.referrer+'">');
		var isValid = true;
		$('input[name]').each(function() {
			if ($(this).val()=='') isValid = false;
		});
		$
		if (!isValid) {
			alert(cmderr);
			return false;
		}
		$.post('/commander.php',$(this).serializeArray(),function() { alert(cmdthx);$('#commander-form').get(0).reset(); });
		return false;
	});
});
