/**
 * @author Patrig Droumaguet
 */
	
function valid_email(email) {
	var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/;
	return (reg.exec(email) != null);
}

function valid_rib(banque, guichet, compte, cle) {
	return (cle == getKey(banque, guichet, compte));
	function getKey(banque, guichet, compte){
		if (5 != banque.length || 5 != guichet.length || 11 != compte.length) 
			return;
		function replaceAlpha(alpha){
			return '12345678912345678923456789'.charAt(alpha.charCodeAt(0) - 65);
		}
		compte = parseInt(compte.toUpperCase().replace(/[A-Z]/g, replaceAlpha), 10);
		return 97 - (((parseInt(banque, 10) % 97 * 100000 + parseFloat(guichet)) % 97 * 100000000000 + compte) % 97) * 100 % 97;
	}
}

jQuery.fn.corners = function(options){
	radius = new Array(0,0,0,0);
	options_radius = options.split(' ');
	for (i = 0; i < options_radius.length; i ++)
	{
		radius[i] = options_radius[i];
	}
	$(this).css('border-top-right-radius', radius[0]).css('-moz-border-radius-topright', radius[0]).css('-webkit-border-top-right-radius', radius[0]).css('-khtml-border-top-right-radius', radius[0]);
	$(this).css('border-bottom-right-radius', radius[1]).css('-moz-border-radius-bottomright', radius[1]).css('-webkit-border-bottom-right-radius', radius[1]).css('-khtml-border-bottom-right-radius', radius[1]);
	$(this).css('border-bottom-left-radius', radius[2]).css('-moz-border-radius-bottomleft', radius[2]).css('-webkit-border-bottom-left-radius', radius[2]).css('-khtml-border-bottom-left-radius', radius[2]);
	$(this).css('border-top-left-radius', radius[3]).css('-moz-border-radius-topleft', radius[3]).css('-webkit-border-top-left-radius', radius[3]).css('-khtml-border-top-left-radius', radius[3]);
	return this;
}

var Utf8 = {
	// Encodage en UTF-8
	encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	},

	// Décodage en UTF-8
	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while ( i < utftext.length ) {
			c = utftext.charCodeAt(i);
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}

function escapeUTF8(s){
    return escape(Utf8.encode(s));
}

function unescapeUTF8(s){
    return Utf8.decode(unescape(s));
}



function change_conditions() {
	$('ul.evenements_non_couverts').toggle('slow');
	if ($('div.evenements_non_couverts h5.sous_titre_page a.opened').length == 1) {
		$('div.evenements_non_couverts h5.sous_titre_page a.opened').removeClass('opened');
	} else {
		$('div.evenements_non_couverts h5.sous_titre_page a').addClass('opened');
	}
}

function sicabol_tip_show(elem) {
	tip_vanish = (new Date()).getTime() + 15000;
	$('div.jQueryTip').html('<img src="' + site_domain + '/media/images/info.png" style="padding-right: 5px;"/>' + $(elem).attr('tip')).attr('vanish', tip_vanish).css('top', $(elem).offset().top + $(elem).height() + 10).css('left', $(elem).offset().left).fadeIn('slow');
	setTimeout('sicabol_tip_vanish()', 15000);
}
function sicabol_tip_hide() {
	$('div.jQueryTip').hide();
}
function sicabol_tip_vanish() {
	if (parseInt($('div.jQueryTip').attr('vanish'), 10) <= (new Date()).getTime()) {
		sicabol_tip_hide();
	}
}

$(document).ready(function() {
	$().mousemove(function(e){
		mouse_X = e.pageX
		mouse_Y = e.pageY;
	});
		
	$('#arrondis_haut_2').corners("10px 0 0 10px");
	
	$('input[type="text"], textarea, select').parents().children('label').addClass('label_form');
	$('input[type="checkbox"]').parents().children('label').addClass('label_form_checkbox');

	$('.sous_boutons li a').css('display', 'block').css('width', '150px');
	
	
	$('body').append('<div class="jQueryTip" style="display: none; position: absolute; z-index: 9999;"></div>');
	$('[tip]').hover(function(){
		sicabol_tip_show(this);
	}, function(){
		sicabol_tip_hide();
	}).focus(function(){
		sicabol_tip_show(this);
	}).blur(function(){
		sicabol_tip_hide();
	});
	$('span[tip]').append('&nbsp;<img src="' + site_domain + 'media/images/info.png" />');
	
	
	$('input[type="text"]').each(function(){
		$(this).val($(this).val().replace(/&amp;/g, '&').replace(/&#039;/g, '\'').replace(/&quot;/g, '"'));
	});

});

