/*(function ($) {
	$.fn.verifForm=function() {
		var jo = select:selected;
		$(this).click(function() {
			if (jo == jo) { alert(jo); };
			});
	};
})(jQuery);*/

// MAP TOOLTIP
function tooltip(laMap, laClass) {
	var nomPays = this.title
	$(laMap +" ."+laClass).mouseover(function(){
			//alert((this).title);
			$('.tooltips').append('<div class="tip_' + laClass + '">'+ this.title +'</div>');
			$("div.tip_" + laClass).fadeIn("fast");
		}).mouseout(function(){
			$("div.tip_" + laClass).fadeOut(200, function() {
				$(this).remove();
				});
		});
	};

// VALUE dans un input FOCUS BLUR
$.fn.labelvalue = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};



// DIV Clickable
(function ($) {
$.fn.hoverCartouche=function() {
	$(this).click(function(){
			window.location=$(this).find('a').attr('href'); return false;
		}).mouseover(function(){
			$(this).css({'background-color':'#dceef8', cursor:"pointer"});
			$(".thumbnail .roundedcorner", this).css({'background-image':'url(/CS/CASINO/img_css/roundedcorner_img_hover.gif)'});
			$("h3 a", this).css({'color':'#994f00','textDecoration':'underline'});
		}).mouseout(function(){
			$(this).css({'background-color':'#fff'});
			$(".thumbnail .roundedcorner", this).css({'background-image':'url(/CS/CASINO/img_css/roundedcorner_img.gif)'});
			$("h3 a", this).css({'color':'#db8716','textDecoration':'none'});
		});
};
})(jQuery);
// SIDE CARTOUCHE
(function ($) {
$.fn.hoverSideCartouche=function() {
	$(this).click(function(){
			window.location=$(this).find('a').attr('href'); return false;
		}).mouseover(function(){
			$(this).css({'background-color':'#ffefac', cursor:"pointer"});
			$("h3 a", this).css({'textDecoration':'underline'});
		}).mouseout(function(){
			$(this).css({'background-color':'#fff'});
			$("h3 a", this).css({'textDecoration':'none'});
		});
};
})(jQuery);


// Création de l'effet fade avec une div
function attachNavEvents(parent, myClass) {
	$(parent + " ." + myClass).mouseover(function() {
		$(this).append('<div class="nav-' + myClass + '"></div>');
		$("div.nav-" + myClass).css({display:"none"}).fadeIn(200);
	}).mouseout(function() {
		// fade out & destroy pseudo-link
		$("div.nav-" + myClass).fadeOut(200, function() {
			$(this).remove();
		});
	}).mousedown(function() {
		$("div.nav-" + myClass).attr("class", "nav-" + myClass + "-click");
	}).mouseup(function() {
		$("div.nav-" + myClass + "-click").attr("class", "nav-" + myClass);
	});
};

// VERTICAL ALIGN
(function ($) {
$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = (ph - ah) / 2;
	$(this).css('margin-top', mh);
	});
};
})(jQuery);

// HORIZONTAL ALIGN
(function ($) {
$.fn.hAlign = function() {
	return this.each(function(i){
	var ah = $(this).width();
	var ph = $(this).parent().width();
	var mh = (ph - ah) / 2;
	$(this).css('margin-left', mh);
	});
};
})(jQuery);

// slide horizontal vers le gauche
(function($) {
	if ($.fn.cycle) {
		$.fn.cycle.transitions.scrollHorz = function($cont, $slides, opts) {
		    $cont.css('overflow','hidden').width();
		//    $slides.show();
		    opts.before.push(function(curr, next, opts, fwd) {
		        $(this).show();
		        var currW = curr.offsetWidth, nextW = next.offsetWidth;
		        opts.cssBefore = fwd ? { left: nextW } : { left: -nextW };
		        opts.animIn.left = 0;
		        opts.animOut.left = fwd ? -currW : currW;
		        $slides.not(curr).css(opts.cssBefore);
		    });
		    opts.cssFirst = { left: 0 };
		    opts.cssAfter = { display: 'none' }
		};
	}
})(jQuery);

// i18n datepicker
jQuery(function($){
	$.datepicker.regional['fr'] = {clearText: 'Effacer', clearStatus: '',
		closeText: 'Fermer', closeStatus: 'Fermer sans modifier',
		prevText: '&lt;Préc', prevStatus: 'Voir le mois précédent',
		nextText: 'Suiv&gt;', nextStatus: 'Voir le mois suivant',
		currentText: 'Courant', currentStatus: 'Voir le mois courant',
		monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin',
		'Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
		monthNamesShort: ['Jan','Fév','Mar','Avr','Mai','Jun',
		'Jul','Aoû','Sep','Oct','Nov','Déc'],
		monthStatus: 'Voir un autre mois', yearStatus: 'Voir un autre année',
		weekHeader: 'Sm', weekStatus: '',
		dayNames: ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
		dayNamesShort: ['Dim','Lun','Mar','Mer','Jeu','Ven','Sam'],
		dayNamesMin: ['Di','Lu','Ma','Me','Je','Ve','Sa'],
		dayStatus: 'Utiliser DD comme premier jour de la semaine', dateStatus: 'Choisir le DD, MM d',
		dateFormat: 'dd/mm/yy', firstDay: 0,
		initStatus: 'Choisir la date', isRTL: false};
	$.datepicker.setDefaults($.datepicker.regional['fr']);
});

// fonctions pour le controle de format sur les dates
function myReplace(str, oldStr, newStr) {

  return str.split(oldStr).join(newStr);
}

function removeLeadingZeros(str) {

  if (str == '')
    return str;
  var i = 0;
  while (i < str.length && str.substr(i , 1) == '0')
    i++;
  if (i == str.length)
    return '0';
  return str.substr(i);
}

function onChangeDate(aField, e, dateSeparator) {

  var unicode=e.charCode? e.charCode : e.keyCode
  if (unicode == 8) {
    return;
  }
  var strDate = aField.value;
  var actualkey = String.fromCharCode(unicode);
  if (myReplace(aField.value , " " , "") == "") {
    if (!isNaN(actualkey) && parseInt(actualkey) > 3) {
        strDate = "0" + strDate;
    }
  } else {
    if (strDate.length >=1) {
        if (strDate.substr(strDate.length - 1, 1) == dateSeparator && actualkey == dateSeparator) {
            strDate = strDate.substr(0, strDate.length - 1);
        }
    }

    if (strDate.length == 1 && actualkey == dateSeparator) {
        strDate = "0" + strDate;
    } else if (strDate.length == 2 && actualkey != dateSeparator) {
        if (strDate.substr(1,1) != dateSeparator) {
            strDate = strDate + dateSeparator;
        }
        if (!isNaN(actualkey) && parseInt(actualkey) > 1) {
            strDate = strDate + "0";
        }
    } else if (strDate.length == 3) {
        if (!isNaN(actualkey) && parseInt(actualkey) > 1) {
             strDate = strDate + "0";
        }
    } if (strDate.length == 4 && actualkey == dateSeparator) {
        strDate = strDate.substr(0,3) + "0" + strDate.substr(3,1);
    } else if (strDate.length == 5 && actualkey != dateSeparator) {
        if (strDate.substr(4,1) != dateSeparator) {
            strDate = strDate + dateSeparator;
        }
    }
  }
  aField.value = strDate;
}

function verifDateFormat(dateValue, dateSeparator) {
    var centuryLimit = 90;
    var srcIndex = new Array(0, 1, 2);
    var unsortedDate = dateValue.split(dateSeparator);

    if (unsortedDate.length != 3) {
        return '';
    }

    for(i = 0; i < 3; i++) {
        if (isNaN(removeLeadingZeros(unsortedDate[i]))) {
            return '';
        }
    }

    var sortDate = new Array(3);

    for(i = 0; i < 3; i++) {
        sortDate[i] = parseInt(removeLeadingZeros(unsortedDate[srcIndex[i]]));
        if (isNaN(sortDate[i])) {
            return '';
        }
    }

    if(sortDate[1] < 1 || sortDate[1] > 12) {
        return '';
    }
	
    if(sortDate[2] < 100) {
        if(sortDate[2] > centuryLimit) {
            sortDate[2] += 1900;
        } else {
            sortDate[2] += 2000;
        }
    }
    var maxDays;
    switch (sortDate[1]) {
        case 2:
          if((sortDate[2] % 4) == 0 && (!((sortDate[2] % 100) == 0) || (sortDate[2] % 400) == 0)) {
            maxDays = 29;
          } else {
            maxDays = 28;
          }
          break;
        case 4:
        case 6:
        case 9:
        case 11:
          maxDays = 30;
        default:
          maxDays = 31;
    }
    if(sortDate[0] < 1 || sortDate[0] > maxDays) return '';
    return sortDate;
}