$(document).ready(function(){
	racine = $('script[src$="head.js"]').attr('src').replace('_scripts/head.js', '');
	
	chaine = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"ombrephoto left\">" +
			"<tbody>" +
			"<tr>" +
			"<td class=\"op_hg\">" +
			"<!--[if IE]><img src=\"./_image/blank.gif\" width=\"6\" height=\"6\" alt=\"\" /><![endif]--></td>" +
			"<td class=\"op_h\"></td><td class=\"op_hd\"><!--[if IE]><img src=\"./_image/blank.gif\" width=\"6\" height=\"6\" alt=\"\" /><![endif]--></td>" +
			"</tr>" +
			"<tr>" +
			"<td class=\"op_g\"></td>" +
			"<td class=\"op_c\">%s</td>" +
			"<td class=\"op_d\"></td>" +
			"</tr>" +
			"<tr>" +
			"<td class=\"op_bg\"></td>" +
			"<td class=\"op_b\"></td>" +
			"<td class=\"op_bd\"></td>" +
			"</tr>" +
			"</tbody>" +
			"</table>";

	$('img.cadre_photo').each(function(){
		chaineImg = '<img src="'+$(this).attr('src')+'" alt="'+$(this).attr('alt')+'" width="'+$(this).attr('width')+'" height="'+$(this).attr('height')+'"';
		$(this).replaceWith(chaine.replace('%s', chaineImg));
	});
	/*
	chaine = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"ombrephoto illustration_dans_colonne_droite\">" +
			"<tbody>" +
			"<tr>" +
			"<td class=\"op_hg\">" +
			"<!--[if IE]><img src=\"./_image/blank.gif\" width=\"6\" height=\"6\" alt=\"\" /><![endif]--></td>" +
			"<td class=\"op_h\"></td><td class=\"op_hd\"><!--[if IE]><img src=\"./_image/blank.gif\" width=\"6\" height=\"6\" alt=\"\" /><![endif]--></td>" +
			"</tr>" +
			"<tr>" +
			"<td class=\"op_g\"></td>" +
			"<td class=\"op_c\">%s</td>" +
			"<td class=\"op_d\"></td>" +
			"</tr>" +
			"<tr>" +
			"<td class=\"op_bg\"></td>" +
			"<td class=\"op_b\"></td>" +
			"<td class=\"op_bd\"></td>" +
			"</tr>" +
			"</tbody>" +
			"</table>";
	
	$('img.illustration_dans_colonne_droite').each(function(){
		chaineImg = '<img src="'+$(this).attr('src')+'" alt="'+$(this).attr('alt')+'" width="'+$(this).attr('width')+'" height="'+$(this).attr('height')+'"';
		$(this).replaceWith(chaine.replace('%s', chaineImg));
	});*/
	
	$('#region_agence').change(function() {
		window.location.href = racine + 'contact/agences-fondasol.php#'+$('select#region_agence option:selected').val();
	});

	$('#reseau_agences').change(function(){
		var redirect = $('#reseau_agences option:selected').val();

		if(redirect == '')
			redirect = racine+'contact/agences-fondasol.php';

		window.location.href = redirect;
	});

	$('#cp_agence').keyup(function(event){
		console.log(event.keyCode);
		if($(this).val() != '' && (event.keyCode == 13 || event.which == 13)){
			findAgence();
		}
	});
});

var addthis_config = {
	ui_click: true
}

function findAgence(){
	
	$.ajax({
		url : racine+'_modules/agence/alias.ajax',
		type:'POST',
		data: {action:'findAgence', cp:$('#cp_agence').val()},
		success:function(url){
			if(url != ''){
				window.location.href = url;
			}
		}
	});
	return false;
}
